• java 遍历arrayList的四种方法


     

    package com.test;

    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.List;

    public class ArrayListDemo {
        public static void main(String args[]){
            List<String> list = new ArrayList<String>();
            list.add("luojiahui");
            list.add("luojiafeng");

            //方法1
            Iterator it1 = list.iterator();
            while(it1.hasNext()){
                System.out.println(it1.next());
            }

            //方法2
            for(Iterator it2 = list.iterator();it2.hasNext();){
                 System.out.println(it2.next());
            }

            //方法3
            for(String tmp:list){
                System.out.println(tmp);
            }

            //方法4
            for(int i = 0;i < list.size(); i ++){
                System.out.println(list.get(i));
            }

        }
    }

  • 相关阅读:
    HDU1263(map)
    Let the Balloon Rise HDU
    PAT甲级1007
    PAT乙级1041
    PAT乙级1037
    PAT乙级1031
    PAT乙级1025
    Hanoi(栈实现)
    《全球资产配置》读后感 读书笔记
    《与内心的恐惧对话》读后感 读书笔记
  • 原文地址:https://www.cnblogs.com/u0mo5/p/4215240.html
Copyright © 2020-2023  润新知