集合的addAll方法--list.addAll(null)会报错--java.lang.NullPointerException

Exception in thread "main" java.lang.NullPointerException

at java.util.ArrayList.addAll(ArrayList.java:559)
at com.iflytek.epdcloud.recruit.utils.quartz.Acool.main(Acool.java:16)

 

import java.util.ArrayList;
import java.util.List;

public class Acool {

    public static void main(String[] args) {
        List <String> b = new ArrayList<>();
        b.add("1");
        b.add("1");
        b.add("1");
        
        List <String> a = new ArrayList<>();
        a.addAll(b);
        a.addAll(null);
        a.toString();
        System.out.println(a);
    }
}

 

posted @ 2018-10-12 17:44  WhoKnows1  阅读(7874)  评论(0编辑  收藏  举报