通过Map的entrySet方法。将返回一个set集合。然后遍历这个set集合:

 

package com.howlaa.day04;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class GenericTest {
	public static void main(String[] args) {
		HashMap<String,Integer> maps = new HashMap<String,Integer>();
		maps.put("zhang", 20);
		maps.put("hui", 22);
		Set<Map.Entry<String,Integer>> entrySet =  maps.entrySet();
		for (Map.Entry<String, Integer> entry : entrySet) {
			System.out.println(entry.getKey()+":"+entry.getValue());
		}
	}
	
}


 

 

相关文章:

  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2019-11-05
  • 2021-07-29
猜你喜欢
  • 2022-02-03
  • 2021-09-30
  • 2022-12-23
  • 2021-08-11
  • 2021-08-06
相关资源
相似解决方案