如何取出Map中key和value的值

如何取出Map中key和value的值,第1张

public static void main(String[] args) {

Map<String, String> map = new HashMap<String, String>();

mapput("1", "v1");

mapput("2", "v2");

for (String key : mapkeySet()) {

Systemoutprintln("key= " + key + " and value= " + mapget(key));

}

}

取key和value

Map map = new Map();Set set = mapentrySet(); Iterator i = setiterator(); while(ihasNext()){ MapEntry entry1=(MapEntry)inext(); Systemoutprintln(entry1getKey()); }这样最终输出的就是map的key值

Set<Integer> keySet = mapkeySet();

for(Integer key : keySet) {

mapget(key);

}

以上就是关于如何取出Map中key和value的值全部的内容,包括:如何取出Map中key和value的值、java map怎么获取key、java获取map中key等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/10206190.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-06
下一篇2023-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存