【发布时间】:2012-06-07 14:33:20
【问题描述】:
线
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() 方法是将点 (\\.) 替换为 (\\\\)。
有人可以解释一下吗?
【问题讨论】: