list1 == list2
To do the above check, will Scala iterate through both lists and call equals on each pair of elements ?
(I am sure, this question has been asked before, but I could not find a good answer with Google & Co)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can find this out yourself for any method by looking at the Scaladoc and finding out where it’s defined, and then looking at the source. If you start with the online docs, you can do this all just with clicking: go to the method, open it up by clicking on the arrow on the left, and you’ll see a list of overriding classes. Go to the first one, and look at the source.
Anyway, in this case,
GenSeqLike, a supertrait ofListand many other collections, definesequalsas acanEqualcheck followed bysameElements. In turn,sameElementschecks whether both arguments areLinearSeqs, and if so, calls equals on each pair of elements by splitting the head and tail apart one by one. Otherwise it defaults to using iterators, callinghasNexton each and then comparing the elements withequals.So, long story short: yes, it calls equals on each pair of elements (stopping as soon as it finds a mismatch).