How to check if array element is null to avoid NullPointerException in Java

后端 未结 9 1054
情深已故
情深已故 2020-12-16 13:08

I have a partially nfilled array of objects, and when I iterate through them I tried to check to see whether the selected object is null before I do other stuff

9条回答
  •  爱一瞬间的悲伤
    2020-12-16 13:35

    The given code works for me. Notice that someArray[i] is always null since you have not initialized the second dimension of the array.

提交回复
热议问题