what is diff string and stringbuffer
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
what is difference between web server and application server?
what are advantages of HQL? what are advantages of Native SQL? what are advantages of Criteria API?
wnet use DAO design in u r project?
Q1. A. Write note on "The class path Environment Variable". B. Which are different kinds of source code? Q2. A. How to create an interface? B. Why convert an applet to an application? Q3. A. How to use Media tracker Class. B. How to use string tokenizer class. Q4. A. Explain the overview of UDP messaging. B. Difference between SQL Exception class and SQL Warning class. Q5. A. How to create com object in Java? B. Write short notes on "The properties class" Q6. A. When object is created and destroyed? B. Explain the JDB in depth & command line. C. Write short notes on Web Sites.
How do you create UserTransaction Object? How do you rollback a transaction in a method?
Which of the following declaration is wrong? int i=45; float j = 45.0; double k=45.0;
What are the uses of the set interfaces in the java collections? : java collections
Hi Friends , am newbie to ajax. For example just consider one account registration - A form contains 8 text fields with submit button. In this form second texbox contains "username " . On right side of text box there is a label box . On clilck action i need to determine user is available or not. Is it possible on clicking label or should i click submit button.
Which is the better framework for web applications, struts or spring, and why?
what is the difference between checked and unchecked Exceptions?
What are the differences between the java collection and the java list? : java collections
what is the diffrence between insurance and telecom domain?