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 anonymous inner class?

587


How do you compare two objects?

497


What is the size of string?

532


What is java virtual machine? Explain

543


What data type is string java?

508






What are drawbacks of singleton class?

505


What are the differences between wait() and sleep()?

515


How can we create a thread in java?

566


How will you print number in reverse (descending) order in BST.

555


What is the final class?

529


What are the differences between checked exception and unchecked exception?

503


What is java reflection?

514


What is difference between an object and a class?

579


What is the purpose of sizeof operator?

508


What does this () mean in constructor chaining concept?

533