首页 > 技术文章 > Map的遍历的方法

narojay 2019-02-11 16:34 原文

#Map的遍历的方法

public class MapForeach {
	public static void main(String[] args) {
		Map<Integer, String> map =new HashMap<>();
		map.put(1, "test1");
		map.put(2, "test2");
		map.put(3, "test3");
		map.put(4, "test4");
		
		for(Map.Entry<Integer, String> entry : map.entrySet()) {
			System.out.println(entry.getKey()+"->"+entry.getValue());
		}
	}
	
	
}

推荐阅读