Day14-09
Shortlist
Stack first-in-first-out, like a cup;
The queue first-in-first-out Fisrt is like a pipe.
Removelast; removefirst
Package test. bixiangdong; import Java. util. shortlist; public class test {private shortlist link; test () {link = new shortlist () ;}// add an elementpublic void add (Object OBJ) {link. add (OBJ);} // first in first out to get an elementpublic object get () {return link. removelast (); // removelast; first out first in; removefirst first in first out} // whether the link is emptypublic Boolean isnull () {return link. isempty ();}/*** @ Param ARGs */public static void main (string [] ARGs) {// todo auto-generated method stubtest T = new test (); t. add ("java1"); T. add ("Java2"); T. add ("java3"); T. add ("java4"); While (! T. isnull () {system. Out. println (T. Get ());}}}
++ ++ ++
Contiue and break
Public static void continuetest () {for (INT I = 0; I <5; I ++) {if (I = 2) {continue;} system. out. println (I); // The result: // 0 // 1 // 2 // 3 // 4} public static void breaktest () {for (INT I = 0; I <5; I ++) {if (I = 2) {break;} system. out. println (I); // The result: // 0 // 1 }}
++ ++ ++
In addition to the standard write of repeated elements in arraylist, note that no exception occurs when the last element is null next.
Package test. bixiangdong; import Java. util. arraylist; import Java. util. iterator; import Java. util. revoke list; public class test {public void singleelement (arraylist Al) {arraylist alnew = new arraylist (); iterator it = Al. iterator (); While (it. hasnext () {object OBJ = it. next (); If (! Alnew. contains (OBJ) {// alnew. add (it. next (); // nosuchelementexception ---------- next () Be sure to pay attention to it, because you take the second time and the last time must be empty alnew. add (OBJ) ;}} Sop (alnew);} public static void Sop (Object OBJ) {system. out. println (OBJ);} public static void main (string [] ARGs) {// todo auto-generated method stubtest T = new test (); arraylist Al = new arraylist (); al. add ("java01"); Al. add ("java01"); Al. add ("java02"); Al. add ("java03"); Al. add ("java04"); T. singleelement (Al );}}