• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

StringBuffer Question???????

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Guru�s

Pls explain to me why the following two Conditions are false.

Thanks, Raghu.K

class Test {
public static void main(String [] argh) {
StringBuffer sb1 = new StringBuffer("abcd");
StringBuffer sb2 = new StringBuffer("abcd");
String s1 = new String("abcd");
String s2 = "abcd";

System.out.println(sb1.equals(sb2)); // Line 1
System.out.println(sb1==sb2);// Line 2

}
}
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ragu:
---> Since StringBuffer class do not implement equals method hence for all equals operations that include StringBuffer objects will return "false"

-----> Two object references created through "new" keyword can't be same. Since == operator just checks the refernces equality. So,If the two references are pointing towards the same object then only == will return true.

Guru???
Swapnil
[ June 27, 2006: Message edited by: Swapnil Trivedi ]
 
RAGU KANNAN
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Guru!!!
    Bookmark Topic Watch Topic
  • New Topic