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.

Before you keep reading...

Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

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.

You have attempted 1 of 5 activities on this page