PackageCn.stat.p3.conection.demo;Importjava.util.ArrayList;Importjava.util.Collection;ImportJava.util.Iterator; Public classConectiondemo {/** * @paramargs*/ Public Static voidMain (string[] args) {//TODO auto-generated Method StubCollection cl=NewArrayList (); Show (CL); } Public Static voidShow (Collection col) {Col.add ("AAA"); Col.add ("BBB"); Col.add ("CCC"); System.out.println (COL); Iterator it=Col.iterator (); while(It.hasnext ()) {System.out.println (It.next ()); } }}
PackageCn.stat.p4.list.demo;Importjava.util.ArrayList;ImportJava.util.Iterator;Importjava.util.List;ImportJava.util.ListIterator;Importjava.util.LinkedList; Public classListdemo { Public Static voidMain (string[] args) {//TODO Auto-generated method stubsLinkedlist<string> nlist=NewLinkedlist<string>(); Show (nlist); } Private Static voidShow (LinkedList nlist) {//TODO Auto-generated method stubsNlist.add ("AAA"); Nlist.add ("BBB"); Nlist.add ("CCC"); System.out.println (nlist); Nlist.add (1, "ddd"); System.out.println (nlist); Listiterator it=Nlist.listiterator (); while(It.hasnext ()) {Object obj=It.next (); if(Obj.equals ("BBB") {It.add ("QQQ"); }}system.out.println (Nlist); System.out.println (It.previous ()); System.out.println (It.previous ()); System.out.println (It.previous ()); /*System.out.println (nlist); System.out.println ("Remove=" +nlist.remove (2)); Nlist.set (2, "QQQ"); System.out.println (); System.out.println (Nlist.get (2));*/ } PublicListdemo () {Super(); //TODO Auto-generated constructor stub }}
Collection How to use