aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about equals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about equals" Watch "about equals" New topic
Author

about equals

Sujittt Tripathyrr
Ranch Hand

Joined: Jun 21, 2006
Posts: 96
Hi

I have doubt in the below code :

1)String s1="Hi";
StringBuffer sb=new StringBuffer("Hi");

2)String s1="Hi";
String sb=new String("Hi");

The 1)returns False but the 2) returns False. Can you explain me why?
Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 356
StringBuffer doesn't override equals.
Nilesh Patel
Ranch Hand

Joined: Feb 02, 2006
Posts: 91
Check it..

http://www.coderanch.com/t/256729/java-programmer-SCJP/certification/Please-help-explain-output-following


Nilesh Patel
SCJP 1.5 - 87%
Kavita Kale
Ranch Hand

Joined: Jan 01, 2006
Posts: 34
Hi sujitt

you have written that

The 1)returns False but the 2) returns False.

2nd point is not false please check that...

in your 1st point you have used stringbuffer that does not override equals() method so it returns false. but String allows you equals() so it returns true .

bye.
Sujittt Tripathyrr
Ranch Hand

Joined: Jun 21, 2006
Posts: 96
Sorry Kavitha

The 2) is True you are right.

I got my answer.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about equals
 
Similar Threads
String and StringBuffer
about "=="and "equals" problem,I can't understand clearely?
StringBuffer and String doubt
String
equals() in Wrapper Classes