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
| package collection;
import java.util.ArrayList; import java.util.Collections; import java.util.List;
public class CollectionMethod { @SuppressWarnings({"all"}) public static void main(String[] args) { List list = new ArrayList();
list.add("wq3stone"); list.add(5); list.add(true);
System.out.println("list=" + list);
list.remove(0); System.out.println("list=" + list); list.remove(true); System.out.println("list=" + list);
System.out.println(list.contains(5));
System.out.println(list.size());
System.out.println(list.isEmpty());
list.clear(); System.out.println(list.isEmpty());
List list2 = new ArrayList(); list2.add("new_element1"); list2.add("new_element2"); list.addAll(list2); System.out.println("list=" + list);
List list3 = new ArrayList(); list3.add("1"); System.out.println(list.containsAll(list3));
list.removeAll(list2); System.out.println(list); } }
|