Map的两种遍历

		HashMap<Integer, String> hm = new HashMap();
		hm.put(1, "张三");
		hm.put(2, "李四");
		hm.put(3, "王五");
		hm.put(4, "赵六");
		System.out.print(hm);
//first
		for(Integer k:hm.keySet()) {
			System.out.print(" "+hm.get(k)+" ");
		}
//second
		System.out.println("------------------");
		Set<Entry<Integer, String>> se= hm.entrySet();
        for(Entry<Integer,String> s :hm.entrySet()) {
	        System.out.print(s.getValue());
        }

猜你喜欢

转载自blog.csdn.net/fuyinghaha/article/details/86519495