在java8中你可以使用 foreach + Lambda拉姆达表达式遍历

package com.qn.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/30 0030.
 */
public class DemoTest {
    public static void main(String[] args) {
        Map<String , String> map = new HashMap<>();
        map.put("a","a");
        map.put("b","b");
        map.put("c","c");
        map.put("d","d");
        map.put("e","e");
        map.put("f","f");

        map.forEach((k,v)->{
            System.out.println("k="+k+",v="+v);
        });

        List<String> list = new ArrayList<>();
        list.add("aaa");
        list.add("bbbbb");
        list.add("ccccccc");
        list.add("dddd");
        list.forEach(v->{
            System.out.println(v);
        });
    }

}

    原文作者:变革心情
    原文地址: https://blog.csdn.net/qiunian144084/article/details/78681154
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞