I\'m trying to replace a character at a specific index in a string.
What I\'m doing is:
String myName = \"domanokz\";
myName.charAt(4) = \'x\';
First thing I should have noticed is that charAt
is a method and assigning value to it using equal sign won't do anything. If a string is immutable, charAt
method, to make change to the string object must receive an argument containing the new character. Unfortunately, string is immutable. To modify the string, I needed to use StringBuilder as suggested by Mr. Petar Ivanov.