We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
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 to List 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.
Other correct answers by the order of arrival were by Heiko Hatzfeld, Jason Kikel, Configurator, Jonathan Gilbert, Justin, Ivan, Justin, Tobi, Jon von Gillern, Jonas Christensen, Ryan Emerle, Damian, Jamie Penney, ecco, Rob R, fred, AdamC, sood, kuldip saini, D.L, Jelle Hissink, Xerxes, Greg and pb.
This weeks question:
You are playing the following game:
Assuming that you gets to start playing first, provide an algorithm that will always win this game. You don’t have to write code, it is much more important that you will explain your solution – how it works and why will it win the game.
Can you solve this problem? Accept the challenge and provide your answers…
Reminder: Comment with answers will not be approved until next weeks challenge (if readers will see the correct answer in one of the comments, it will become pointless).
Tags :ArrayListBoxingchallengeCoinsjob interviewObjecctOpponentquestionTableValuType
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd