It's not a secret anymore!* The moose likes Programmer
Certification (SCJP/OCPJP) and the fly likes comparison Big
Moose Saloon Register / Login Bookmark "comparison" Watch
"comparison" New topic   ameen ahamed  Joined: Jan 02, 2001
Posts: 25 class test public static void main(String args[]){
Byte b1=new Byte("127"); if(b1.toString()==b1.toString())
System.out.println("True"); why this fragment prints false ?
Sharada Kumaran  Joined: May 23, 2001 Posts: 29 My guess is that
b1.toString() and b2.toString() return two different String
objects. Khaled says " Each wrapper class overrides the
toString() method. The overriding method returns a String object
representing the primitive value. " In this case, b1.toString()
and b2.toString(), maybe returning two objects, each occupying a
different memory location, but having the same value. The
operator == is comparing for object equality, and not value
equality. On the other hand, returns true. Please correct me if
my understanding is wrong.  Samith Nambiar Ranch Hand