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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
| public class CollectionTest {
@Test public void test1(){ Collection coll = new ArrayList(); coll.add(123); coll.add(456);
coll.add(new Person("Jerry",20)); coll.add(new String("Tom")); coll.add(false); boolean contains = coll.contains(123); System.out.println(contains); System.out.println(coll.contains(new String("Tom")));
System.out.println(coll.contains(new Person("Jerry",20)));
Collection coll1 = Arrays.asList(123,4567); System.out.println(coll.containsAll(coll1)); }
@Test public void test2(){ Collection coll = new ArrayList(); coll.add(123); coll.add(456); coll.add(new Person("Jerry",20)); coll.add(new String("Tom")); coll.add(false);
coll.remove(1234); System.out.println(coll);
coll.remove(new Person("Jerry",20)); System.out.println(coll);
Collection coll1 = Arrays.asList(123,456); coll.removeAll(coll1); System.out.println(coll);
}
@Test public void test3(){ Collection coll = new ArrayList(); coll.add(123); coll.add(456); coll.add(new Person("Jerry",20)); coll.add(new String("Tom")); coll.add(false);
Collection coll1 = new ArrayList(); coll1.add(456); coll1.add(123); coll1.add(new Person("Jerry",20)); coll1.add(new String("Tom")); coll1.add(false);
System.out.println(coll.equals(coll1));
}
@Test public void test4(){ Collection coll = new ArrayList(); coll.add(123); coll.add(456); coll.add(new Person("Jerry",20)); coll.add(new String("Tom")); coll.add(false);
System.out.println(coll.hashCode());
Object[] arr = coll.toArray(); for(int i = 0;i < arr.length;i++){ System.out.println(arr[i]); }
List<String> list = Arrays.asList(new String[]{"AA", "BB", "CC"}); System.out.println(list);
List arr1 = Arrays.asList(new int[]{123, 456}); System.out.println(arr1.size());
List arr2 = Arrays.asList(new Integer[]{123, 456}); System.out.println(arr2.size());
} }
|