String are immutable in Java.
(字符串在Java中是不可变的。)
You can't change them. (您不能更改它们。)
You need to create a new string with the character replaced.
(您需要创建一个新字符串并替换字符。)
String myName = "domanokz";
String newName = myName.substring(0,4)+'x'+myName.substring(5);
Or you can use a StringBuilder:
(或者,您可以使用StringBuilder:)
StringBuilder myName = new StringBuilder("domanokz");
myName.setCharAt(4, 'x');
System.out.println(myName);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…