我编码为我Applictation抛出NullPointerException,我碰到一个要求,在这里我需要字符串转换为字符数组我为什么它不在这种情况下
String str_a = "Testing";
char c[] = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
像我一样未初始化char c[]
我的问题是,为什么不抛出一个NullPointerException
,通常应该这样做这样
char[] char_array = new char[str_a.length()];
char_array = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
谢谢,这是很好的解释 – Pawan 2012-03-30 17:54:57