why String class is immutable.
Answers were Sorted based on User's Feedback
Answer / vikrant
Once a string object is created no changes can be made to
it. If a string is modified in code a new object will be
created. That is why string is immutable
Is This Answer Correct ? | 24 Yes | 7 No |
Answer / 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 |
Answer / kirthika
everytime a string object is created, it enters into the string pool and thereby this concept was mainly to enhance the response time if the same string is used elsewher..
therefore string class is immutable..
Is This Answer Correct ? | 4 Yes | 4 No |
Answer / naru
String object is immutable that's why security maintain of
file chech .when connection is establic first os check the
String object if string is mutable that is big pain in
security issue...
Is This Answer Correct ? | 2 Yes | 4 No |
Answer / rakesh
For save the memory and reduce the response time.
StringBuffer provide an alternet for String class object,
which is muttable.
Is This Answer Correct ? | 5 Yes | 9 No |
What is thread pool? How can we create thread pool in java?
Difference between nested and inner classes ?
What are the object and class classes used for?
What is java and its types?
what is the life cycle of jsp?
What is rmi and steps involved in developing an rmi object?
what are the rules to use try catch finally?
Differentiate between stringbuffer and string?
1) Find the Merge point of two linked lists. 2) Swap two bits of integer. 3) Reverse individual words of the sentence. 4) Reverse string without using temp string.
Can we instantiate Interfaces?
what should do when using multiple catch() block & what should never do for the same?
What is the difference between Synchronizing mehtod & Synchronizing block?