why String class is immutable.

Answer Posted / rakesh soni

Any Program have 'Performance' and 'Memory' issue.
1. If you want to save your 'memory' then use the 'String'
class but 'Performance' will be decrease, because every time
new object create and old object memory collect by Garbage
Collector, so performance decrease.
And
2. If you want 'Performance', than use 'StringBuffer' or
'StringBuilder' object. These class's object consume more
memory but not create new object, so 'Performance' will
increase but with memory overhead.

So take decision according your code and issue. :)

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the synchronized method modifier?

846


What is the difference between abstract classes and interfaces?

788


What does a boolean method return?

873


How will you reverse a singly-link list?

776


Will the jvm load the package twice at runtime?

833


What is meant by data hiding/encapsulation?

812


What is string literal in java?

775


What is the return type of the main method?

790


What are the 6 boolean operators?

778


Which is better 64 bit or 32 bit?

695


What is ascii format?

765


When should you use arraylist and when should you use linkedlist?

699


What happens if an exception is not handled in a program?

848


What is keyword and identifier?

876


I want to persist data of objects for later use. What is the best approach to do so?

807