public static void main(String[] args) {
char[] array = new char[2];
array[0] = 'a';
String s = new String(array);
assert s.length() == 2;
System.out.print(">" + s + "<\n");
System.out.print(">" + s.substring(1) + "<\n");
System.out.print("end of test.\n");
}
的输出是:如果Java打印NUL字符会怎么样?
>a
>
end of test
不同于C,在Java字符串不是空字符结束,因此断言是真实的。为什么Java不打印<
分隔符号?
编辑:可能相关的是,这是在Eclipse 4.5.1在Ubuntu 14.04。
它为我打印出来。它可能是你的终端导致它吗? – resueman
对我来说很好用 –
对我来说也适用 – mhyst