[Logo]
Forums Register Login
String and String buffer difference
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]
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.
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
 

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.
thanks Raghavan Muthu

i got it now

thanks
one more doubght.

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


Regards,
Biny Balan
 
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/
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards



All times above are in ranch (not your local) time.
The current ranch time is
Nov 25, 2017 03:06:18.