4.3. Strings are Immutable

Even though you can manipulate a string to create a new string the original string is immutable which means that it doesn’t change. Notice that after you execute the code below the string stored in the variable sentence hasn’t changed.

While the strings themselves can’t be changed you can change the value of a variable. This throws away the original string and sets the variable’s value to the new string.

Before you keep reading...

Runestone Academy can only continue if we get support from individuals like you. As a student you are well aware of the high cost of textbooks. Our mission is to provide great books to you for free, but we ask that you consider a $10 donation, more if you can or less if $10 is a burden.

Note

Discuss topics in this section with classmates.

Show Comments
You have attempted 1 of 5 activities on this page