[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}