To replace a character at a specified position
public class Main {
public static void main(String args[]) {
String str = "this is a test";
System.out.println(replaceCharAt(str, 5, 'c'));
}
public static String replaceCharAt(String s, int pos, char c) {
return s.substring(0, pos) + c + s.substring(pos + 1);
}
}
//this cs a test
Related examples in the same category