Java replace the string at the specified position in the string
Use StringBuilder:
String str1="123456789你好.jpj";
StringBuilder sb=new StringBuilder(str1);
sb.replace(str1.length()-6, str1.length()-4, "nihao");
String str2=sb.toString();
System.out.println(str2);
Output result:
123456789nihao.jpj