Top "Immutability" questions

Immutability is the inability to modify data after it has been created.

What is difference between mutable and immutable String in java

As per my knowledge, a mutable string can be changed, and an immutable string cannot be changed. Here I want …

java string immutability mutable stringbuffer
Aren't Python strings immutable? Then why does a + " " + b work?

My understanding was that Python strings are immutable. I tried the following code: a = "Dog" b = "eats" c = "treats" print …

python string immutability mutability
Enums in Javascript with ES6

I'm rebuilding an old Java project in Javascript, and realized that there's no good way to do enums in JS. …

javascript enums ecmascript-6 immutability symbols
Replace Multiple String Elements in C#

Is there a better way of doing this... MyString.Trim().Replace("&", "and").Replace(",", "").Replace(" ", " ") .Replace(" ", "-").Replace("'", "").Replace("/", "").…

c# string refactoring immutability
Immutable array in Java

Is there an immutable alternative to the primitive arrays in Java? Making a primitive array final doesn't actually prevent one …

java arrays immutability
Why .NET String is immutable?

As we all know, String is immutable. What are the reasons for String being immutable and the introduction of StringBuilder …

c# .net string immutability
What is the difference between shallow copy, deepcopy and normal assignment operation?

import copy a = "deepak" b = 1, 2, 3, 4 c = [1, 2, 3, 4] d = {1: 10, 2: 20, 3: 30} a1 = copy.copy(a) b1 = copy.copy(b) c1 = copy.copy(c) d1 = …

python copy variable-assignment immutability deep-copy
Examples of immutable classes

I already know the definition of immutable classes but I need a few examples.

java immutability
Error: "Cannot modify the return value" c#

I'm using auto-implemented properties. I guess the fastest way to fix following is to declare my own backing variable? public …

c# variables struct immutability
Immutability of Strings in Java

Consider the following example. String str = new String(); str = "Hello"; System.out.println(str); //Prints Hello str = "Help!"; System.out.…

java string immutability