标签: java string printing console
我希望将字符串打印到控制台,重要的是要看到确切的字符串,这意味着它应该在日志中显示换行符\n。所以它将是"this is the exact sequence of chars \n"
\n
"this is the exact sequence of chars \n"
答案 0 :(得分:1)
您可以将所有\n字符替换为\\n(打印时显示为\n)。
\\n
String str = "this is the exact sequence of chars \n"; System.out.print(str.replace("\n", "\\n");