I will give you one of the approach that maybe not the best (You can go research it why is that the case). But I think this is one of the simple example for you.
If I have string "hello" and I need to replace 'l' with 'y' which result to "helyo", I will use this following:
String word = "hello"; String toBeReplaced = "l"; String toReplace = "y"; String newWord = word.replace(toBeReplaced, toReplace); newWord = newWord.replaceFirst(toReplace, toBeReplaced); System.out.println(newWord);