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
What is the basic of java?
What is the static method?
What does 0 mean in boolean?
How many inner classes can a class have?
Which package is imported by default?
Why do we need hashmap in java?
What is the difference between int and integer in java?
What is double word?
Why string is not a wrapper class?
What are constants?
Define a package.
Define an enumeration?
What is generics in java interview questions?
Why is logger singleton?
Is it necessary for the port addresses to be unique? Explain with reason.