Someone on stackoverflow gave this code that finds the position of chars… Now the problem is, its a loop that searches the whole string and returns each position… Now in this code an example “pool” is used. So it returns 1 and 2
String s = "Pool";
int idx = s.indexOf('o');
while (idx > -1) {
System.out.println(idx);
idx = s.indexOf('o', idx + 1);
}
Is there a way to use both positions returned in a method and replace the chars… For instance if I wanted to replace the ‘o’ with ‘hh’ resulting in ‘phhl’
I would recommend the solution by @Sujay, but just in case that does not meet your requirement…