1//short answer: you cannot individually change any specific character
2//of a String in java. You can however do this:
3
4String s1 = "This is a String";
5String s2 = s1.substring(0, 8) + "o" + s1.substring(9);
6System.out.println(s2);
7//Prints "This is o String", replaced the 8th character with an o
1String str = "..............................";
2
3 int index = 5;
4
5 char ch = '|';
6
7 StringBuilder string = new StringBuilder(str);
8 string.setCharAt(index, ch);
9
10 System.out.println(string);
1public class JavaExample{
2 public static void main(String args[]){
3 String str = new String("Site is BeginnersBook.com");
4
5 System.out.print("String after replacing com with net :" );
6 System.out.println(str.replaceFirst("com", "net"));
7
8 System.out.print("String after replacing Site name:" );
9 System.out.println(str.replaceFirst("Beginners(.*)", "XYZ.com"));
10 }
11}