the replaceAll() method consume a regex for the 1st argument.
String str2= str1.replaceAll("^", "\""); the ^ in String str2= str1.replaceAll("^", "\""); will match the starting position within the string. So if you want the ^ char, write \^
Hope this code can help:
String str = "hello \"there"; System.out.println(str); // hello "there String str1 = str.replaceAll("\"", "^"); System.out.println(str1); // hello ^there String str2= str1.replaceAll("\\^", "\""); System.out.println(str2); // hello "there