//removeAll()方法
private static void testList(){
List<String> list = new ArrayList<String>();
List<String> list1 = new ArrayList<String>();
list.add("123");
list.add("456");
list1.add("123");
list.removeAll(list1);
Iterator<String> iterator = list1.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
}
//clear()方法
private static void testList(){
List<String> list = new ArrayList<String>();
List<String> list1 = new ArrayList<String>();
list.add("123");
list1.add("123");
list.add("456");
list.clear();
Iterator<String> iterator = list.iterator();
while(iterator.hasNext()){
System.out.println(iterator.next());
}
if(list == null){
System.out.println("null");
}else if(list.size()==0){
System.out.println("list不为null"+"元素个数为"+list.size());
}else{
System.out.println("仍有元素");
}
}