File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Byte class(Wrapper class) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Byte class(Wrapper class)" Watch "Byte class(Wrapper class)" New topic
Author

Byte class(Wrapper class)

lalitha kaparapu
Greenhorn

Joined: Nov 05, 2007
Posts: 16
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
Marshal

Joined: Mar 22, 2005
Posts: 41835
    
  63
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Byte class(Wrapper class)