aspose file tools*
The moose likes Beginning Java and the fly likes String and String buffer difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String and String buffer difference" Watch "String and String buffer difference" New topic
Author

String and String buffer difference

biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
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]


Biny Balan
binypanackal@gmail.com
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

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.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
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

Joined: Apr 20, 2006
Posts: 3344


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

Joined: Apr 12, 2007
Posts: 72
thanks Raghavan Muthu

i got it now

thanks
biny panackal
Ranch Hand

Joined: Apr 12, 2007
Posts: 72
one more doubght.

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


Regards,
Biny Balan
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42277
    
  64
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/


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String and String buffer difference