This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Byte class(Wrapper class)" Watch "Byte class(Wrapper class)" New topic

Byte class(Wrapper class)

lalitha kaparapu

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");
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41052
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
jQuery in Action, 2nd edition
subject: Byte class(Wrapper class)
Similar Threads
* Byte == comparision
Byte and String
String Question
related to "=="