what is diff string and stringbuffer

Answers were Sorted based on User's Feedback

what is diff string and stringbuffer..

Answer / monika

string is immutable, that is it can not be extended.whereas
StringBuffer is mutable and can be extended.
Fro example :
Consider 2 statement : "Welcome " and "to Java World".
now assign first statement to string and string buffer.
String str = "Welcome" & StringBuffer strBuff = new
Now if we add 2nd statement to both then :
str= str + "to Java World" -> In this case, it would dump
all the memory allocated with "welcome" and allocate a new
memory space to the entire string "Welcome to Java World" .
On the other hand, in strBuff :-
strBuff.append("to Java World") -> if simply allocate a
new memory space to only 2nd statement and add to link to
previous name.

Is This Answer Correct ?    51 Yes 7 No

what is diff string and stringbuffer..

Answer / gayathri

String is immutable that once the value assigned to object
cannot be modified.Suppose if we want to perform
concatenation another string object will be prepared and
the value is going to assign for that object.in total we
are having 2 objects

StringBuffer is Mutable we can change the value of the
object even the value is assigned to the object.

Is This Answer Correct ?    29 Yes 2 No

what is diff string and stringbuffer..

Answer / kesavaraj

Simple Example for String And String Buffer.

String must allow the declared memory space to the variable.

String Buffer automatically increase the Exists memory space

Is This Answer Correct ?    18 Yes 2 No

what is diff string and stringbuffer..

Answer / rohit aggarwal

String is Immutable and String buffer is mutable.
Inside String.java, equals() method is overrideen but not
the case in StringBuffer.

This all is the simple.

Is This Answer Correct ?    13 Yes 2 No

what is diff string and stringbuffer..

Answer / aashish r. wadhokar

string is immutable,that we can not be modify its value.
when we assign any new value to String variable.a new object
is created on heap memory and that string variable refers to
that object.

StringBuffer is mutable so we can be modify its value.
as it refers to the same object and changes the state of
that object

Is This Answer Correct ?    5 Yes 3 No

what is diff string and stringbuffer..

Answer / rahul shukla

string class is to mainpulate character strings that can not be changed.
string buffer._-- class is used to represent character that can be modified.

Is This Answer Correct ?    1 Yes 1 No

what is diff string and stringbuffer..

Answer / sudheer babu

Both string and string buffer are different ,in the case of
the String it can ready only and immutable where as the
String Buffer is the modifier and mutable.
String s1="abc";
S.o.p(s1);---------->o/p is abc
StringBuffer sb=new StringBuffer("abc");
s.o.p(sb);---------->o/p is abc
here we can modify the String buffer values if we want i.e
s.o.p(sb);----------->0/p is abcz

"this is the basic difference between the String and String

Is This Answer Correct ?    8 Yes 9 No

Post New Answer

More Java J2EE AllOther Interview Questions

my interviewer asked me what technical specification you used how to answer that question

0 Answers  

what is class/object diagram

3 Answers   Zycus Infotech,

Write a interface "CarOperations" with the following methods void turnOnEngin() void turnOffEngin() void turnOnLigths() void turnOffLights() void turnLeft() void turnRight() void accelerate() void deaccelerate() void putBreaks() void releaseBreaks()

1 Answers  

what is filter ?

2 Answers   SolutionNET,

What is IOC in spring?

10 Answers   Centris,

What is the use of the list interface in the java collection? : java collections

0 Answers  

I have include a jsp page by using <jsp:include page="/.../xyz.jsp"/> The thing is that the xyz.jsp page has its submit button.When i click on that button the whole main page get refreshed.But i want to refresh only the xyz.jsp page.How could i achive it so that i can only refresh the xyz.jsp not the main page page?

4 Answers  

What are the types of interface used in the java collections? : java collections

0 Answers  

what is diff string and stringbuffer

7 Answers   CTS, HCL,

What is the difference between Eclipse and MyEclipse?

7 Answers   IBM, Wavex,

whats the relation ship between LDAP and JNDI?

1 Answers  

which book is the best for preparing for SCWCD 1.5

4 Answers   Google,