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
Is hashset sorted in java?
Distinguish between a predicate and a function?
How will you reverse a link list without using recursion?
What is main function purpose?
Is string passed by reference in java?
How to solve the problem of generating the unique hash keys with hash function?
How can I debug the Java security exceptions and AccessControlExceptions?
What is difference between jdk,jre and jvm?
Which arithmetic operations can result in the throwing of an arithmeticexception?
Explain the concept of proper inheritance?
What is the difference between private & public & friendly classes?
How you can force the garbage collection?
What is the method overriding?
What are the differences between forwarding () method and sendredirect() methods?
Is integer passed by reference in java?