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 are adapter classes?

603


Can java arraylist hold different types?

498


How would you convert bytes to string?

566


Which of the following classes will have more memory allocated?

587


What is a double?

591






What is the java project architecture?

1787


What is final, finally, finalize?

600


What state is a thread in when it is executing?

529


What is oop in java?

533


Why is whitespace important?

557


Can a class extend more than one class?

616


Is null function in java?

570


How to perform binary search in java?

574


What is a nested structure?

540


What is 16 bits called?

503