why String class is immutable.

Answers were Sorted based on User's Feedback



why String class is immutable...

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

why String class is immutable...

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

why String class is immutable...

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

why String class is immutable...

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

why String class is immutable...

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

Post New Answer

More Core Java Interview Questions

What is a numeric digit?

0 Answers  


Tell some latest versions in JAVA related areas?

0 Answers  


what is the difference between System.exit() and System.exit(1)?

1 Answers   eClinical Solutions, eClinical Works, eClinicalWorks,


Where is jre installed?

0 Answers  


What is the size of integer?

0 Answers  






In Inheritance if we are implementing Multi level inheritance and all class having same name of variable and now i want to access each class variable and how it is possible?

2 Answers  


Java openings 3 - 5 years, Lnt Infotech. requirements - core java, J2ee, struts, hibernate Interview Date:- 19 March 2011 Time:- 9:00 AM to 12:00 Pm Interview Location - L & T Infotech, Manapakkam, Chennai Refererral PS NO:- 291649 (Please mention this when u fill the form only then u will be considered for interview) Documents Required:- Latest Resume, Photograph and last 3 payslips Mail me on vasan2211@gmail.com once u appear for interview

0 Answers   L&T,


Which class has no duplicate elements?

8 Answers  


What are the important features of Java 8 release?

0 Answers  


What is CardLayout?

1 Answers   Infosys,


What super () does in java?

0 Answers  


What is the java project architecture?

0 Answers   IBM,


Categories