我編碼爲我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