I have java class that will call recursive method for string replace. The method will return the string after replacing all required character one by one. But this not working as expected. Please find the code below.
public class TestingRecursion {
private static String startRecursion(String value){
value = value.replaceFirst("a", "b");
if(value.contains("a"))
startRecursion(value);
return value;
}
public static void main(String[] args) {
String value = "1a 2a 3a 4a";
String afterRecursion = startRecursion(value);
System.out.println(afterRecursion);
}
}
Expected output - "1b 2b 3b 4b" Actual output - "1b 2a 3a 4a".