本文共 1183 字,大约阅读时间需要 3 分钟。
import java.util.List;import java.util.ArrayList;class ListDemo{ @SuppressWarnings(value="unchecked") public static void main(String[] args){ List list = new ArrayList(); list.add(100); list.add(new Integer(200)); list.add("one"); list.add(new String("two")); list.add(new Student("one",'M',18)); list.add(new Student("two",'F',18)); Student student = new Student(); student.setName("three"); student.setSex('F'); student.setAge(100); list.add(student); List list_repeat = new ArrayList(); list_repeat.add(100); list_repeat.add(student); Boolean bool_list = list.containsAll(list_repeat);//包含list_repeat集合 Boolean bool_obj = list.contains(student);//包含student对象 list.remove(0);//移出集合第0个元素 list.remove(student);//移出集合中的student对象的元素 list.removeAll(list);//清空集合 System.out.println(bool_list); System.out.println(bool_obj); System.out.println(list.size()); System.out.println("----------"); Student s = null; for(int i=0;i
转载于:https://blog.51cto.com/senlinmin/1774387