Directory Freebies VS CheatSheet Forum

RSS

Email

Translate

Home About Archive Privacy Contact Advertise Write for Dev102

That’s it, Times up on the sixth in the series of job interview questions. There were 39 people who answered and the first one to give a correct answer was leppie from the IronScheme project.

The correct answer is that both will return false.

You could sum up the answer by saying Boxing.

An ArrayList hold objects, so when you insert a ValueType into it, it will be boxed and become an object. When you compare List[0] to List[1] you are comparing references, and they will never be the same because they are pointing to different objects. This is the reason for getting the false in both comparison. It is true that in the second comparison you are comparing a double and an int ( 2.0 and 2), but that is not why you get false, it is due to the Boxing.


Continue Reading...
Write Article for Dev102

Write for Dev102!

We pay for user submitted tutorials and articles that we publish. Anyone can send in a contribution

Learn More