• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

String and StringBuffer class

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !!
Could u pls throw some more light over similarities between String and StringBuffer class and super and sub concept. Is String a sub class of StringBuffer class ??
Thanx in advance.
Anukampa
 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
1.String class and StringBuffer class :Both extends Mother of all superclass
Object.Both are final , public.Both implements Serializable.
............
2.String implements Comparable<too>..This is immutable.That means
once created you can not change it's content.
StringBuffer is not so.
3.super() to call Superclass Constructor from subclass constructor.
this() is to call the same within the same class.
Both can not be used at the same time...Rest later...regards..NM
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String overrides equals methods StringBuffer doesn't. Hence equals used on the StringBuffer always returns false.
String does not have methods : append, insert, delete as StringBuffer has.
StringBuffer does not have concat, trim methods that String has.
 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bharatesh :
I could u pls explin yr statement which says "String overrides equals methods StringBuffer doesn't".
Thanx
Anukampa
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Object class defines a equals method. String class and many other classes (such as Wrapper classes etc) override equals method.
For eg
String a = "string";
String b = new String (a);
the if check with == returns false as a and b are in different memory locations. equals check for the equality of contents. Hence :
if (a.equals(b)) returns true. But if a class (StringBuffer) does not override this method then the equals method behaves like a check for ==. That is equals does a shallow comparison.
Hope I am not confusing ...
 
Anu
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx again Bharatesh. I have got yr point.
Anukampa
 
yeah, but ... what would PIE do? Especially concerning this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic