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 class is a data type?
Can you make a constructor final in Java?
Explain the difference between jvm and jre?
What is boolean false?
Explain the difference between intermediate and terminal operations in java8?
How do you check if a number is a perfect square?
When do you get classcastexception?
What is a ternary operator in java?
Can the garbage collection be forced by any means?
What is space character in java?
java program with complete 4 oops concepts implemented example
What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?
What is the use of private static?
Give us the name of the list layoutmanagers in java?
Detail discussions on JVM, memory management and garbage collector.