java.util.List与null对象

        List list = new ArrayList();
        System.out.println(list.size()); // 0
        System.out.println(list.isEmpty()); // 1
        System.out.println(list.get(0)); // java.lang.IndexOutOfBoundsException

        list.add(null);
        System.out.println(list.size()); // 1
        System.out.println(list.isEmpty()); // false
        System.out.println(list.get(0)); // null

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.