Strings are immutable. Which is a jargon shorthand for saying that an instance of String will not change its characters (think "leopard" and "spots").
There are two ways you can go. One is to build up a new string based on sentence
. There are lots of methods in the String
class that will help. Once you have that newly constructed string you assign it to sentence
The other way is not to use String at all, but prefer StringBuilder
. As you can see from its docs a StringBuilder instance is
mutable: ie there are methods provided to alter the characters it contains. If you are altering the contents of a sequence of characters a lot (eg Hangman or similar), StringBuilder might be more useful.