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
|
public class CollectionTest { @Test public void test1(){ ArrayList<Object> list = new ArrayList<>(); list.add(123); list.add(456); list.add(new String("Tom")); list.add(false); list.add(new Person("Jerry",12)); for (Object list1:list){ System.out.println(list1); }
boolean contains = list.contains(123); System.out.println(contains); System.out.println(list.contains(new String("Tom"))); System.out.println(list.contains(new Person("Jerry",12)));
System.out.println(list.containsAll(list));
list.remove("Tom"); list.remove(new Person("Jerry",12)); for (Object list2:list){ System.out.println(list2); }
System.out.println(list);
List<Integer> asList = Arrays.asList(123, 456, 789); System.out.println(list);
ArrayList<Object> list3 = new ArrayList<>(); list.add(123); list.add(456); list.add(false); System.out.println(list.equals(list3)); }
@Test public void test5(){ ArrayList<Object> list = new ArrayList<>(); list.add(123); list.add(456); list.add(new String("Tom")); list.add(false); list.add(new Person("Jerry",12));
System.out.println(list.hashCode());
Object[] arr = list.toArray(); for (Object o:arr){ System.out.println(o); }
List<String> list1 = Arrays.asList(new String[]{"AA", "BB", "CC"}); System.out.println(list1);
} }
|