List<Integer> list = Lists.newArrayList(1,2,3);
List<Integer> list2 = null;
//throws nullPointer
list.addAll(list2);
//check here
if (list2!=null){
list.addAll(list2);
}
Is there a Java 8 way of doing it simple in one-line.
This is one I have. but I actually don't need the boolean created.
boolean added = list2!=null ? list1.addAll(list2) : false