Found this website to presumably test wannabe developers...
http://www.devchallenge.co.uk/challenge-2
The question is this...
Based on the given code, which of the following tests will return a ‘true’ answer and pass, and which will return a ‘false’ answer and fail?
ArrayList array1 = new ArrayList();
ArrayList array2 = new ArrayList();
array1.add(1);
array1.add(2);
array1.add("Aviva");
array2.add(1);
array2.add(2.0);
array2.add("Aviva");
Asserts
Equality
(array1[0],array2[0]);
Asserts
Equality
(array1[1],array2[1]);
Asserts
Equality
(array1[2],array2[2]);
Apparently the answer is 'Fail', 'Fail', 'Pass'.
I'm not a Java developer - and I am presuming this challenge is in Java (though it isn't stated).
What exactly is Equality doing? Is it checking for the same object or the same value? I know that some objects are interned into the String/Integer pool in Java and so I can understand why the last one is true. But why is the first one not true?