I am not understanding how to use the String.replace() method. Here is the code:
CharSequence oldNumber = "0";
CharSequence newNumber = "1";
String example = "folderName_0";
System.out.println("example = " + example);
example.replace(oldNumber, newNumber);
System.out.println("example.replace(oldNumber, newNumber);");
System.out.println("example = " + example);
And it's outputting:
example = folderName_0
example.replace(oldNumber, newNumber);
example = folderName_0 // <=== How do I make this folderName_1???
The
replace
method isn't changing the contents of your string;String
s are immutable. It's returning a new string that contains the changed contents, but you've ignored the returned value. Changewith