Package Collection;import Java.util.linkedlist;/*linkedlist: Unique method AddFirst ()/addlast (); GetFirst ()/getlast (); Removefirst ()/removelast (); If the list is empty, throw no exception to this element/nosuchelementexception but the JDK1.6 version has an alternative method: Offerfirst ()/offerlast () ;p Eekfirst ()/peeklast () Pollfirst ()/polllast (): Returns the Null*/public class Linklistdemo{public static void main If the list is empty ( String[] args) {linkedlist<string> link = new linkedlist<string> () Link.addfirst ("Java01"); Link.addfirst ("Java02"); Link.addfirst ("Java03"); Link.addfirst ("Java04"); SOP (link); [Java04, Java03, Java02, Java01]/*get method takes only the element remove method to complete the element, but also deletes *//*sop (Link.getfirst ()); SOP (Link.getlast ()); SOP ( Link.removefirst ()), SOP (Link.removelast ()), SOP ("Size:" +link.size ()), */while (!link.isempty ()) {SOP ( Link.removefirst ());}} public static void Sop (Object obj) {System.err.println (obj);}} /////////////////////////////////////////////////////////////////////////////////////////////////////////////// /package collection;import java.util.linkedlist;/* using LinkedList to simulate a stack or queue data structure。 Stack: Advanced out queue: FIFO */class duilie{private linkedlist link;duilie () {link = new LinkedList ();} public void Myadd (Object obj) {link.addfirst (obj);} Public Object MyGet () {return link.removelast ();} public Boolean isNull () {return link.isempty ();}} public class Linklisttest{public static void Main (string[] args) {Duilie dl = new Duilie ();d l.myadd ("Java01");d L.myadd (" Java02 ");d l.myadd (" Java03 ");d l.myadd (" Java04 ");//System.out.println (Dl.myget ()); System.out.println ("============"), while (!dl.isnull ()) {System.out.println (Dl.myget ());}}}
Java LinkedList Proprietary method Pee && simulates a stack or queue data structure using LinkedList.