• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String and String buffer difference

 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I am a bgnr java. I read that there is two class in java for string handling. I tried to get its differences but now able to find a satisfying solution. I hope you people can help me out. String class objects can store multiple character and also we can apply string functions for concatenating then the actual size of the string will be get differences . but some where i read that this is the difference
Can any body help to get out of this chaos situation.

Regards,
Biny Balan
[EMAIL]binypanackal@gmail.com [/EMAIL]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Biny,

Were you intended to ask the "difference between String and StringBuffer"? In this case, Strings in Java are IMMUTABLE and StringBuffers are MUTABLE.

For the explanation of the same concept with example, please look at this thread !

HtH.
 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Ragav

then you are saying that after the following operation

String s = "Sample";
s += " String";
System.out.println("s is : "+s);

The object s will refer a new object...
if so what happen to the first reference



Regards,
Biny Panackal
binypanackal@gmail.com
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The object s will refer a new object..


Perfectly correct!


if so what happen to the first reference


There is nothing like first reference, second reference. The first or original object being referred by the reference variable "s" will be eligible for garbage collection IF there are NO active references for it. Means, if there are no refernece variables pointing to that object.

HtH.
 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Raghavan Muthu

i got it now

thanks
 
biny panackal
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more doubght.

wether the StringBuffer class have all the methods used by String class. Like indexOf(),lastIndexOf() etc...


Regards,
Biny Balan
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by biny panackal:
wether the StringBuffer class have all the methods used by String class. Like indexOf(),lastIndexOf() etc...


The fastest way to find out which methods are available in a particular class is to look it up in the javadocs: http://java.sun.com/j2se/1.5.0/docs/api/
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic