In Java, the string is immutable and cannot be replaced. so To solve the problem, you can create a new string with a specific index changed and substitute it.
String myName = "domanokz";
String newName = myName.substring(0,4)+'x'+myName.substring(5);
Like this. If you don't like it, use StringBuilder
StringBuilder myName = new StringBuilder("domanokz");
myName.setCharAt(4, 'x');
System.out.println(myName);
You can do it like this.
© 2024 OneMinuteCode. All rights reserved.