• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

stringbuffer equals

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following copied from poddar test.
1. StringBuffer sb1 = new StringBuffer("Amit");
2. StringBuffer sb2= new StringBuffer("Amit");
3. String ss1 = "Amit";
4. System.out.println(sb1==sb2);
5. System.out.println(sb1.equals(sb2));
6. System.out.println(sb1.equals(ss1));
7. System.out.println("Poddar".substring(3));
why line no.5 & 6 gives result false.
thanx in adv
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gopala,
StringBuffer class do not override equals() method. Hence the comparison is done not for the contents of the objects but for the object references and since these are two distinct objects with distinct references, the result is false.
The reason 6 is false for the same reason as mentioned above. Except ss1 is on pool and not on heap.
-Sandeep Nachane
------------------
Visit my homepage at
www.tipsmart.com
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic