• 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

equals() in StringBuffers

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Can anybody please help me with this topic. Here is the code
StringBuffer sb1 = new StringBuffer("abc");
 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Sorry for that incomplete message!
Can anybody please help me with this topic. This code returns false but I don't understand why?
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer("abc");
System.out.println(sb1.equals(sb2));
Is there any example, in which equals() method in case of StringBuffer returns true.
Thanks in advance,
KN
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by KN:
Hi!
Sorry for that incomplete message!
Can anybody please help me with this topic. This code returns false but I don't understand why?
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer("abc");
System.out.println(sb1.equals(sb2));
Is there any example, in which equals() method in case of StringBuffer returns true.
Thanks in advance,
KN


StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = sb1;
System.out.println(sb1.equals(sb2));
StringBuffer doesn't override equals() in Object, so it only test to see if the references refer to the same object.

 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Carl.
Are there any classes other than String & Wrapper classes which override equals() method?
KN
 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any taker of my above Question?
Thanks
KN
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the other classes, I know of, that override equals method are wrapper classes Boolean, Integer, Float etc.
Date also overrides equals method but it is not required for the exam.
satish
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Refeer to Java API Documentation. Switch to index mode and look for equals(Object) signature. There are a few dozen classes which override equals method.
Ajith
 
KN
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajith,
Where can I find the Java API Documentation?
Thanks
KN
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic