ImportJava.util.*;/*LinkedList: Unique method: AddFirst (); AddLast (); GetFirst (); GetLast (); Gets the element without deleting it. If there are no elements in the collection, Nosuchelementexceptionremovefirst () is present, removelast () is obtained, but the element is deleted. If there are no elements in the collection, Nosuchelementexception appears in the JDK1.6 alternative method. Offerfirst (); Offerlast ();p eekfirst ();p eeklast (); Gets the element without deleting it. If there are no elements in the collection, NULL is returned. Pollfirst ();p olllast (); Gets the element, but the element is deleted. If there are no elements in the collection, NULL is returned. */classLinkedlistdemo { Public Static voidMain (string[] args) {LinkedList link=NewLinkedList (); Link.addlast ("Java01"); Link.addlast ("Java02"); Link.addlast ("Java03"); Link.addlast ("Java04"); //sop (link);//SOP (Link.getfirst ());//SOP (Link.getfirst ()); //SOP (Link.getlast ()); //SOP (Link.removefirst ()); //SOP (Link.removefirst ()); //SOP ("size=" +link.size ()); while(!Link.isempty ()) {SOP (Link.removelast ()); } } Public Static voidsop (Object obj) {System.out.println (obj); }}/*---java01java02java03java04----java04java03java02java01---*/
Java Collection Collection-list-linkedlist