字符串的 replaceAll() 方法和转义字符
生产线
System.out.println("\\");
打印单个反斜杠 ()。和\
System.out.println("\\\\");
打印双反斜杠 ()。理解!\\
但为什么在下面的代码中:
class ReplaceTest
{
public static void main(String[] args)
{
String s = "hello.world";
s = s.replaceAll("\\.", "\\\\");
System.out.println(s);
}
}
是输出:
hello\world
而不是
hello\\world
毕竟,该方法是将点 () 替换为 ()。replaceAll()
\\.
\\\\
有人可以解释一下吗?