Myślałem żeby zrobić tak jak niżej przy użyciu substring, ale jak pozycja będzie ostatnim indexem w tekście to nastąpi wyjście poza zakres, więc trzeba dodać kolejnego ifa, a nie ma jakiejś metody, która by po prostu zmieniała literę w stringu pod danym indexem?
String tekst = "abcde";
String nowy_tekst = null;
String pozycja = 4;
if(tekst.charAt(pozycja) == 'a') nowy_tekst = tekst.substring(0, pozycja) + "11" + tekst.substring(pozycja+1);
else nowy_tekst = tekst.substring(0, pozycja) + "22" + tekst.substring(pozycja+1);