+ 1

Can anyone help me in understanding the Java code which is attached here?

why output is helloworld why not helloworldhello https://code.sololearn.com/cHQZojT4rbl8/?ref=app

29th Apr 2017, 7:26 AM
Player
Player - avatar
4 Answers
+ 9
Because the value of the Integers are the same, but they're not the same objects in memory. == compares the memory refence. You can compare the values with the valueOf method of Integer.
29th Apr 2017, 7:51 AM
Tashi N
Tashi N - avatar
+ 9
You're welcome.
29th Apr 2017, 7:58 AM
Tashi N
Tashi N - avatar
+ 3
But when the values assigned to Integer range from (-128 to 127)... the == returns true ,when they are same. https://code.sololearn.com/c8a4P26uYmbG/?ref=app
29th Apr 2017, 8:00 AM
Manideep
Manideep - avatar
+ 2
got it. thank you mam
29th Apr 2017, 7:55 AM
Player
Player - avatar