All of the above answers may be correct. However, replacing each row once is inefficient. The following code from Apache Commons StringUtils will help it efficiently replace all strings in one go.
System.out.println("Input String:\n");//// Scanner keyboardScanner = new Scanner(System.in);///// String inString = keyboardScanner.nextLine();///// StringUtils.replaceEach(inString, new String[]{"call me", "as soon as possible"}, new String[]{"cm", "asap"});
Please note that: the above method does not work when replacing words in the previous replacement result. For instance:
StringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"})
will give the result: "dcte"
source share