Difference between String and StringBuffer.
Answer Posted / geetha
String and StringBuilder class stores strings. But when you
cannot change a String object after creating one.
eg: String name = "Prasad";
By saying you cannot change the name object means you cannot
change the value in name object internally. When you change
the name object value to something else, a new String object
is creating in memory and assign the new value.
eg: name = "Prasad Reddy";
A new name object is creating in memory and the value
"Prasad Reddy" is assinging to the newly created space.
But StringBuilder class occupies the same space even if you
change the value.
If you are doing string concatenation StringBuilder class is
far better in performance than String class.
You can use StringBuilder's Append() method to use
concatenation.
| Is This Answer Correct ? | 5 Yes | 0 No |
Post New Answer View All Answers
What is return keyword in java?
What is a instance variable in java?
What is the purpose of the system class in java?
How many bytes are a float?
What is a superclass?
How many types of java are there?
Where and how can you use a private constructor?
What is difference between java and java ee?
When we should use serialization?
Explain access modifiers in java.
Differentiate storage classes on the basis of their scope?
What are the states of thread in java?
How does split work in java?
What is equlas() and hashcode() contract in java? Where does it used?
What mechanism does java use for memory management?