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


Please Help Members By Posting Answers For Below Questions

What is the best way to findout the time/memory consuming process?

554


Explain creating threads by extending thread class ?

574


Why java strings are immutable in nature?

586


What does 3 dots mean in java?

513


What is java’s garbage collected heap?

531






What are the restrictions imposed on method overriding?

550


Explain importance of inheritance in java?

604


What is the difference between Grid and Gridbaglayout?

577


Why java is said to be pass-by-value ?

542


What is an immutable object?

578


What is string made of?

525


What is wrapper class html?

526


what do you mean by classloader in java?

566


What is Java Shutdown Hook?

608


Why java is a platform independent? Explain

529