Collection常用方法
由于Collection是一个接口,无法进行实例化,我们可以通过继承了的子类ArrayList进行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| package Learn;
import java.util.ArrayList; import java.util.List;
public class Test { public static void main(String[] args) { List list=new ArrayList(); list.add("jack"); list.add("10"); list.add(12); System.out.println(list); list.remove(0); System.out.println(list.remove("10")); System.out.println(list); System.out.println(list.contains(10)); System.out.println(list.contains(12));
System.out.println(list.size()); System.out.println(list.isEmpty());
list.clear(); System.out.println(list.size()); List list2=new ArrayList(); list2.add(100); list2.add(10); list2.add("骄傲成"); list.addAll(list2); System.out.println(list); System.out.println(list.containsAll(list2));
System.out.println(list.removeAll(list2));
} }
|