How to find length of a string array?

前端 未结 8 1199
温柔的废话
温柔的废话 2020-12-13 19:10

I am having a problem with the following lines where car is a String array which has not been initialized/has no elements.

String c         


        
8条回答
  •  一个人的身影
    2020-12-13 19:43

    This won't work. You first have to initialize the array. So far, you only have a String[] reference, pointing to null.

    When you try to read the length member, what you actually do is null.length, which results in a NullPointerException.

提交回复
热议问题