String str = ".............................."; int index = 5; char ch = '|'; StringBuilder string = new StringBuilder(str); string.setCharAt(index, ch); System.out.println(string);