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
StringBuffer("Welcome");
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.

whereas
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.
EX:
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
sb.append("z");
s.o.p(sb);----------->0/p is abcz

"this is the basic difference between the String and String
Buffer."

Is This Answer Correct ?    8 Yes 9 No

Post New Answer

More Java J2EE AllOther Interview Questions

wnet use DAO design in u r project?

1 Answers   Godrej,


what debugging tool that can be used to debug the java programs?

1 Answers   Inforica,


What is the difference between comparable and comparator in java.util pkg?

0 Answers  


Runining mutiple tomcat server in a single machine is possible Yuo wil have to duplicate configuration with different port numbers

2 Answers   HCL,


Should we create system software ( e.g operating system ) in java ?

0 Answers  


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

0 Answers  


When to use the Collection Classes(HashSet, LinkedHashSet, TreeSet....etc) in real time scenario ?

1 Answers   Cap Gemini,


what are callback methods?

3 Answers   iFlex,


2. Write a interface "Car" with the following methods void setName(String) String getName() void setColor(String) String getColor() void setModel(long) long getModel()

1 Answers  


Difference b/w >> and >>> ?

1 Answers   Adobe, Infosys,


Which of the following declaration is wrong? int i=45; float j = 45.0; double k=45.0;

5 Answers   Adobe,


What is Generic in java? Where can we write Generic ( class or method or objects or etc...)? with simple example? Thanks, Bose. Infosys 2 In which way does a Primitive data type is passed ? Sun- Microsystems 4 what is the use of declaring constructor as private? Sai- Softech 5 what is difference between global methods and local methods? 1 What is meant by class loader and how many types are there? Apple 1 what is meaning of JIT? 4 What is an abstract class? Wipro 5 what is filters and its use? Virtusa 2 why is multiple inheritance not allowed in java? Elementus-Technologies 7 Differences between jdk 1.4 and 1.5 Wipro 4 is JVM platform dependent or independent..? IBM 6 what is main purpose of abstract class? 5 what is difference between colection and collections? Tech-Mahindra 11 What error occurs if a try-catch-finally statement sequence does not have a catch clause? 2 Explain the difference between scrollbar and scrollpane? 1 Explain the differences between public, private, protected and static? 4 Explain the difference between getAppletInfo and getParameterInfo? 1 Is Cegonsoft Pvt.Ltd. a good Institute? 4 Why only one Class is public in one file? Explain in details. Thanks in Advance. 11 Which method will get invoked first in a stand alone application?

0 Answers  


Categories