packagetd.com;importjava.util.*;publicclassDemo{publicstaticvoidmain(String[] args){ArrayList list =newArrayList();
list.add(0,"k");
list.add(1,"kk");
list.add(2,"kkk");
list.add(3,"x");
list.add(4,"xx");
list.add(5,"xxx");
list.add(6,"q");
list.add(7,"qq");
list.add(8,"qqq");System.out.println("Size of the tree set is: "+list.size());// int size();//返回集合长度System.out.println(list.isEmpty ());// boolean isEmpty ();//返回集合是否为空System.out.println(list.contains("kk"));// boolean contains(Object o);//返回集合是否包含这个元素System.out.println(list.indexOf("xx"));// int indexOf(Object o);//返回指定元素 第一次出现的下标Object[]a=list.toArray();System.out.println(list);System.out.println(list.toArray());System.out.println(a[4]);// object [ ] toArray( );//将集合变成数组System.out.println(list.get(6));// E get (int index);//根据下标获取元素System.out.println(list.set(1,1));// E set (int index,E element);//在制定下标位置插入元素System.out.println(list.add(123));// boolean add(E e);//添加一个元素System.out.println(list.remove(1));// E remove (int index) ;//根据下标移除元素
list.remove("100");System.out.println(list.remove("k"));// boolean remove(Object o);//移除元素/* list.clear();
System.out.println(list.size());//清空集合
*/}}
packagetd.com;importjava.util.LinkedList;publicclassDemo3{publicstaticvoidmain(String[] args){LinkedList linkedList=newLinkedList();//向链表集合添加元素
linkedList.add(0,"00");
linkedList.add(0,"11");
linkedList.addFirst("22");
linkedList.addFirst("33");
linkedList.addFirst("44");
linkedList.addFirst("55");System.out.println(linkedList);System.out.println(linkedList.getFirst());// E getFirst();//获取头节点System.out.println(linkedList.getLast());// E getLast();//获取尾节点
linkedList.removeFirst();System.out.println(linkedList.getFirst());// E removeFirst();//移除头节点
linkedList.removeLast();// E removeLast();//移除尾节点
linkedList.remove("33");
linkedList.addFirst("88");// addFirst(E e);//头插法
linkedList.addLast("99");// void addLast(E e);//尾插法
linkedList.contains("66");// boolean contains(Object o);//是否包含某个元素
linkedList.size();// int size();//返回链表的长度
linkedList.add("1111");// boolean add(E e);//添加元素 调用的尾插法
linkedList.remove("22");// boolean remove(Object o);//移除某个元素
linkedList.clear();// void clear();//清空集合中的元素
linkedList.get(5);// E get(int index);//获取元素System.out.println(linkedList);}}