• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about equals

 
Sujittt Tripathyrr
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
StringBuffer doesn't override equals.
 
Nilesh Patel
Ranch Hand
Posts: 91
 
Kavita Kale
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Kavitha

The 2) is True you are right.

I got my answer.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic