怎么样获取key里面的value

2025-05-07 14:34:06
推荐回答(1个)
回答1:

*/public class Test_Map {
public static void main(String[] args) throws Exception {
Map map = new HashMap();
map.put("one", 1);map.put("two", 2);
map.put("three", 3);
//得到value的方法
System.out.println("========得到value的方法========");
Collection c = map.values();
System.out.println(c);
Iterator iter1 = (Iterator)map.values().iterator();
while(iter1.hasNext()){
System.out.println(iter1.next());}//得到key的方法
System.out.println("========得到key的方法========");
Collection s = map.keySet();
System.out.println(s);
Iterator iter2 = (Iterator)map.keySet().iterator();