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 programs use java?

464


What's the difference between an abstract class and interface in java?

548


What does I ++ mean?

590


What is meant by class?

532


How to create an interface?

621






What are synchronized methods and synchronized statements in java programming?

564


How do you compare objects in java?

491


Why java is secure? Explain.

581


What classes of exceptions may be caught by a catch clause in java programming?

690


What is the importance of finally block in exception handling?

530


What is java instanceof operator?

552


How do I remove a character from a string in java?

487


Explain the difference between jvm and jre?

552


What are the drawbacks for singleton class?

512


What are the advantages of arraylist over arrays?

557