Arrays.asList与Arrays.stream 创建长度为0的数组

参考网址:https://www.cnblogs.com/baby123/p/12619872.html

创建长度为0的数组:

    public static void main(String args[]){
        Integer[] integer = new Integer[0];
        System.out.println(integer.length);
    }

  

运行结果:0

做一下对比,创建一个为null的空数组

    public static void main(String args[]){
        Integer[] integer = null;
        System.out.println(integer.length);
    }

  

运行结果:

Exception in thread "main" java.lang.NullPointerException
at com.zyq.Test.main(Test.java:28)

 

posted on 2021-06-16 17:27  ~码铃薯~  阅读(132)  评论(0编辑  收藏  举报

导航