我正在尝试以下代码:-
String x = "asdfg/dgws";
x.replaceAll("/", "\\");
但这是失败的。这给了我以下错误消息:-
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 1
at java.lang.String.charAt(Unknown Source)
at java.util.regex.Matcher.appendReplacement(Unknown Source)
at java.util.regex.Matcher.replaceAll(Unknown Source)
at java.lang.String.replaceAll(Unknown Source)
at com.jai.SecLargest.main(SecLargest.java:13)
我无法弄清楚为什么会出现这个异常?