Results 1 to 3 of 3
Thread: Why String is immutable in java?
- 03-07-2012, 07:08 PM #1
Member
- Join Date
- Feb 2012
- Posts
- 5
- Rep Power
- 0
- 03-07-2012, 07:10 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Why String is immutable in java?
For one thing: a String couldn't serve as a key in a Map<String, ?> nor can substrings share their char buffers.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-07-2012, 07:20 PM #3
Re: Why String is immutable in java?
Also, how would using String literals make sense? What happens if you do this?
Java Code:System.out.println("cats"); //prints cats, okay "cats".add(" and more cats"); //since Strings are mutable, this appends the String? System.out.println("cats"); //this now prints out something other than the literal?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
Why string is immutable in java?
By jessie143143 in forum Reviews / AdvertisingReplies: 0Last Post: 10-15-2011, 02:47 PM -
String Immutable
By jomypgeorge in forum New To JavaReplies: 18Last Post: 12-17-2010, 11:54 AM -
Strings and Immutable
By al_Marshy_1981 in forum New To JavaReplies: 19Last Post: 06-18-2010, 07:22 AM -
What is Immutable in String
By elektronika in forum New To JavaReplies: 4Last Post: 12-10-2009, 12:58 PM -
What is an Immutable Class
By maheshkanda in forum New To JavaReplies: 3Last Post: 02-06-2009, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks