[BXD learning Java Basics] 8. An encapsulation of the shortlist can be a stack and a queue. In one sentence, we can see that continue and break ++ in addition to the repeated standard syntax of arraylist ++

Source: Internet
Author: User

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 );}}

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.