String.replaceAll() can be used with String
public class Main { public static void main(String args[]) { // Remove all \n with empty string System.out.println("\r\n\t\b".replaceAll("\n", "")); // Replace \n by \r System.out.println("\r\n\t\b".replaceAll("\n", "\r")); } }