1. package test;
    2. import java.util.Iterator;
    3. import java.util.LinkedList;
    4. import java.util.List;
    5. public class ListFor {
    6. @SuppressWarnings({"all"})
    7. public static void main(String[] args) {
    8. //List 接口的实现子类 Vector LinkedList
    9. //List list = new ArrayList();
    10. //List list = new Vector();
    11. List list = new LinkedList();
    12. list.add("jack");
    13. list.add("tom");
    14. list.add("鱼香肉丝");
    15. list.add("北京烤鸭子");
    16. //遍历
    17. System.out.println("=====迭代器=====");
    18. //1. 迭代器
    19. Iterator iterator = list.iterator();
    20. while (iterator.hasNext()) {
    21. Object obj = iterator.next();
    22. System.out.println(obj);
    23. }
    24. System.out.println("=====增强for=====");
    25. //2. 增强for
    26. for (Object o : list) {
    27. System.out.println("o=" + o);
    28. }
    29. System.out.println("=====普通for====");
    30. //3. 使用普通for
    31. for (int i = 0; i < list.size(); i++) {
    32. System.out.println("对象=" + list.get(i));
    33. }
    34. }
    35. }

    image.png