This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
When i run the program it returns "Not Equal" . The problem is when i change the value 11 as 10. The output it was generating "Equals". Can any one tells why it behaves different when we change the value.
everytime i run this code the output is "Not Equal" ....
Joined: Feb 01, 2008
Thanks For the very quick reply.
I am using the RAD6.0 Where it was Showing "Not Equals" and "Euals". After your reply i checked with jdk5.0. Where its showing "Not Equals" "Not Equals" when i change the value 11 as 10. LEt me investigate where the exact issue.
In this example Java's pass-by-value and reference related knowledge is queried?
If you compile and run this code like below, it will print "Equals".
But if you compile and run as your code, it always prints out "Not Equals". This is because i.toString() creates different objects everytime and equality operator checks this objects if they are referencing the same.