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
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
Can we instantiate interface in java?
Can we have multiple classes in single file ?
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
What is purpose of find feature?
What are the 2 types of java programs?
What are generic methods?
What is the main use of generics in java?
How many types of memory areas are allocated by jvm?
Can a final method be overloaded?
What is unicode in java?
Under what conditions is an object’s finalize() method invoked by the garbage collector?
What Is Composition?
why java does not support unsigned keyword?
What are sets in java?