Difference between String & StringBuffer
Answer Posted / vijayakumar chinnasamy
String :
1.Content does not change –immutable
2.final class (cant subclass)
3.compareTo() - compare the string
result : < , > , = --- dictionary order
4.reverse() not available
5.is not thread safe
Criteria to choose among String
If your text is not going to change use a string Class
because a String object is immutable.
StringBuffer:
1. Content can be change Mutable
2.Final class.
3. compareTo() Not available
4.reverse() available
Allocates room for 16-addition character space when no
specific length is specified.
5.is thread safe
Criteria to choose StringBuffer
If your text can changes, and will be accessed from
multiple threads, use a StringBuffer because StringBuffer is
synchronous
| Is This Answer Correct ? | 52 Yes | 9 No |
Post New Answer View All Answers
Difference between start() and run() method of thread class?
Can we create our own wrapper class in java?
What is compiler and what its output.
What is nullpointerexception in java?
What technique can be employed to compare two strings?
What does null mean in java?
What is maximum size of arraylist in java?
Explain polymorphism citing an example.
What is unicode full form?
Who developed java?
Is java a pure object oriented language?
Can a static member function access member variable of an object?
What is the disadvantage of java?
Does java arraylist maintain insertion order?
What does the ‘static’ keyword mean? Is it possible to override private or static method in java?