I am writing a method that returns a String with the specified letter doubled but it only returns the original value of s. I am relatively new to java and think this is due to Strings being immutable in java but I am not sure how to work around it. Any help with this method would be appreciated.
public static String doubleSpecificLetter(String s, String letter){
String s2 = s;
for(int i = 0 ; i < s2.length() ; i++) {
if(s.substring(i, i + 1) == letter) {
s2 = String.join(letter, s2.substring(0, i + 1), s2.substring(i + 1));
}
}
return s2;
}