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

Explain treeset?

562


What is prefix of a string?

538


What is the role of garbage collector in java?

474


Can a final method be overloaded?

483


Is 0 true or false?

488






Can a static class implement an interface?

525


What is data member in java?

483


What are the basic control structures?

478


What are controls and their different types in awt?

576


Can we assign null to double in java?

518


What is adapter in java?

493


Can you run java program without main method?

528


Why for each loop is used?

484


How do I start learning java?

533


What is compareto () in java?

514