This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
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.
 
Have you checked out Aspose?
 
subject: Byte class(Wrapper class)
 
It's not a secret anymore!