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 reflection?

788


What state is a thread in when it is executing?

738


What is parsing a string?

849


How do you escape a string?

736


What comes to mind when someone mentions a shallow copy in java?

899


What is the difference between and ?

708


describe synchronization in respect to multithreading? : Java thread

720


What is the difference between member variables initialization and assignment in a constructor?

928


Explain the differences between abstraction and encapsulation?

807


Tell us something about an iterator.

737


Will the jvm load the package twice at runtime?

848


Which are different kinds of source code?

897


What are triggers in DB? Explain their types. How do they work?

878


What is a boolean output?

733


Difference between predicate, supplier and consumer ?

818