This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Java in General and the fly likes String class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "String class" Watch "String class" New topic
Author

String class

Arpit Chaudhary
Greenhorn

Joined: Dec 28, 2007
Posts: 7
what is the reason to make String class immutable.......?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Welcome to the Ranch.

Have you read the API documentation for String? That is so you can use the same String object in several different places. If you have a String like "Arpit" you can pass it around your application in different classes and different threads secure in the knowledge that it will still say "Arpit" when you have finished.
If a String were mutable it would require a new String every time you used it, otherwise your String "Arpit" could mysteriously change to "Campbell" when you don't expect it.

Anybody able to explain it better than me?
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1510
May be you would like to see this one...

http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html



Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String class
 
Similar Threads
String Q
Split Method in String Class
More then the specified answer?
How String Can Be A Reference Variable...
How to remove spaces from string