这就是我试过的......
public void printArray()
{
for(int i = 0; i<size; i++)
{
System.out.println("arr[" + i + "] = " + arr[i]);
}
}
这就是我得到的:
-arr[0] = Papa Bill
-arr[1] = Ali Baba
-arr[2] = Ming the Merciless
-arr[3] = Grandpa
-arr[4] = Tornado
-arr[5] = null
我需要它打印出null ...
答案 0 :(得分:3)
只需在for循环中添加null检查:
if ( arr[i] != null ){
System.out.println("arr[" + i + "] = " + arr[i]);
}