Are immutable strings better?

Nov 14, 2009 at 2:20am
and why? the string class in c++ is not immutable but in java it is, my lecturer said he prefers immutable strings, is there any reason that immutable strings are better?
Nov 14, 2009 at 3:35am
Well that depends on what you're trying to accomplish. To make a string immutable in C++ you declare it as a const. const string name;. If you need to be able to change the string object in the future, then obviously you would not want to make it immutable. But if you don't need to change it, then const, is appropriate.

my lecturer said he prefers immutable strings


How could he prefer immutable strings? It depends on the need.
Topic archived. No new replies allowed.