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 happens if an exception is throws from an object's destructor?

590


Can we nested try statements in java?

632


What is sizeof () operator?

573


Why destructor is not used in java?

526


How to overcome the exception object reference not set to an instance of object?

630






What is java util function?

521


How can you add and remove nodes in jtree?

619


Can static method access instance variables ?

609


What does string [] args mean?

544


What is a final class in java?

551


If a method is declared as protected, where may the method be accessed?

540


What is string in java with example?

495


What is the difference between state-based unit testing and interaction-based unit testing?

500


What is a default constructor and also define copy contrucyor?

607


what is thread? : Java thread

561