zoukankan      html  css  js  c++  java
  • 遍历list集合的三种方式

            List<String> list1 = new ArrayList<String>();
            list1.add("1");
            list1.add("2");
            list1.add("3");
            list1.add("4");
            // 1、普通话for循环
            String res = "";
            for (int i = 0; i < list1.size(); i++) {
                res += list1.get(i);
            }
            System.out.println(res);
            // 2、增强for
            String res2 = "";
            for (String item : list1) {
                res2 += item;
            }
            System.out.println(res2);
            // 3、使用迭代器遍历
            Iterator<String> it = list1.iterator();
            String res3 = "";
            while (it.hasNext()) {
                res3 += it.next();
            }
            System.out.println(res3);
  • 相关阅读:
    灌注和宝石性道法价比分析
    bzoj1912
    bzoj3504
    poj3580
    bzoj1251
    bzoj3223
    bzoj1212
    bzoj3790
    记一次惨痛的比赛
    bzoj2734
  • 原文地址:https://www.cnblogs.com/wms01/p/7532477.html
Copyright © 2011-2022 走看看