[Java learning notes] & lt; Collection framework & gt; one of the unique listing methods, java learning notes

Source: Internet
Author: User

[Java learning notes] <Collection framework> one of the unique listing methods, java learning notes

1 import java. util. arrayList; 2 import java. util. iterator; 3 import java. util. list; 4 5 public class Test2 {6 7 public static void main (String [] args) {8 List list = new ArrayList (); 9 10 list. add ("abc1"); 11 list. add ("abc2"); 12 list. add ("abc3"); 13 list. add ("abc4"); 14 15 show1 (list); // use the iterator to retrieve 16 show2 (list ); // one of the methods for listing specific elements to be retrieved 17 18} 19 20 21 // one of the methods for listing specific elements to be retrieved 22 public static void show2 (list) {23 for (int x = 0; x <list. size (); x ++) {24 System. out. println ("get:" + list. get (x); 25} 26} 27 28 // use Iterator fetch method 29 public static void show1 (List list) {30 Iterator it = list. iterator (); 31 while (it. hasNext () {32 System. out. println ("next:" + it. next (); 33} 34} 35 36}

 

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.