public static String template = "$A$B"
public static void somemethod() {
template.replaceAll(Matcher.quoteReplacement("$")+"A", "A");
template.replaceAll(Matcher.quoteReplacement("$")+"B", "B");
//throws java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3
template.replaceAll("\\$A", "A");
template.replaceAll("\\$B", "B");
//the same behavior
template.replace("$A", "A");
template.replace("$B", "B");
//template is still "$A$B"
}
我不明白。我尝试了所有在互联网上找到的替换方法,包括所有我能找到的Stack Overflow的方法。我甚至尝试了\u0024!出了什么问题?