How to find length of a string array?

前端 未结 8 1192
温柔的废话
温柔的废话 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:27

    As all the above answers have suggested it will throw a NullPointerException.

    Please initialise it with some value(s) and then you can use the length property correctly. For example:

    String[] str = { "plastic", "paper", "use", "throw" };
    System.out.println("Length is:::" + str.length);
    

    The array 'str' is now defined, and so it's length also has a defined value.

提交回复
热议问题