File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes why String class is immutable? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "why String class is immutable?" Watch "why String class is immutable?" New topic
Author

why String class is immutable?

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
why javasoft need to keep Sting class immutable?
and why StringBuffer is mutable?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12324
    
    1
The Java designers recognized that many many security holes are created by sloppy handling of strings. Therefore they made modification of an existing string variable impossible. This also has other advantages - for example the intern() method saves storage space.
Bill
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
...and given that String is immutable, the reason for the existence of StringBuffer should be obvious -- sometimes you want to be able to alter a sequence of characters.


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: why String class is immutable?
 
Similar Threads
Strign.replace() replaceAll()
Math class immutable
why immutable string object ?
why string
String and wrapper classes