1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package collection;
import java.util.ArrayList; import java.util.Iterator; import java.util.List; @SuppressWarnings("all") public class EnhanceFor { public static void main(String[] args) { List col = new ArrayList(); col.add(new Book("西游记","吴承恩",44.6)); col.add(new Book("红楼梦","曹雪芹",38.9)); col.add(new Book("水浒传","罗贯中",66.6)); Iterator it = col.iterator(); while(it.hasNext()) System.out.println(it.next()); System.out.println("================="); for(Object book : col){ System.out.println(book); }
int[] nums = {1,4,7,3,2}; for(int num : nums){ System.out.print(num + " "); } } }
|