@Test public void ListTest(){ List list = new ArrayList(); int size = list.size(); System.out.println(size); System.out.println(list); //向集合中添加元素 list.add(0,"zero"); list.add(1,"one"); list.add(2,2); list.add(3,'3'); list.add(4,3.14); System.out.println(list); List list1 = new ArrayList(); list1.add("two"); list1.add(10); list1.addAll(list1); System.out.println(list); System.out.println("-----------------------"); // Object o = list.get(3); System.out.println(o); // o = list.set(0,1); System.out.println("下标为0的位置修改为:" + o); System.out.println(list); // o = list.remove(0); System.out.println("删除的元素为:" + o); System.out.println("-----------------"); System.out.println(list); List list2 = list.subList(0,3); System.out.println("List集合:" + list); System.out.println("子集合中的元素:" + list2); list2.remove(0); System.out.println("List集合:" + list); System.out.println("子集合中的元素:" + list2); }
@Test public void collectionTest02(){ Collection<String> collection = new ArrayList<>(); collection.add("AA"); collection.add("BB"); collection.add("BB"); collection.add("DD"); System.out.println(collection); }
@Test public void queueTest(){ //准备一个Queue集合 Queue<Integer> queue = new LinkedList<>(); //将数据11 22 33 44 55依次入队并打印 for (int i = 1; i <= 5; i++){ queue.offer(i * 11); System.out.println(queue); } //然后查看队首元素并打印 Integer it = queue.peek(); System.out.println("队首元素:" + it); //然后将队列中所有数据依次出队并打印 System.out.println("-------------------------"); //poll int len = queue.size(); for (int i = 1; i <= len; i++){ Integer it1 = queue.poll(); System.out.println(it1); } }