Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Byte class(Wrapper class)

 
lalitha kaparapu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried a code like this.But surprisingly I found that output is false instead of true..Can anyone help in this regard???
class Test{
public static void main(String args[])
Byte b1 = new Byte("127");
if(b1.toString==b1.toString)
System.out.println("True");
else
System.out.println("False");
}
}
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

String equality is tested by the String.equals method, not by the == operator. Try "b1.toString().equals(b1.toString())".

Since the toString method creates a new string every times it's called, the objects you're comparing are not equal in the "==" sense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic