简体   繁体   English

如何从 map 获取键和值,并使用 Java8 方法对每个键和值执行某些操作

[英]How to get the key and value from map and perform certain operation on each key and value using Java8 methods

How to get the key and value from map and perform certain operation on each key and value using Java8 methods如何从 map 获取键和值,并使用 Java8 方法对每个键和值执行某些操作

I got some methods but it helps only to print the message(using System.out.println),but I want to perform some operations(finding duplicates in value,comparing values using casting etc.,) in each key/value pair我有一些方法,但它只有助于打印消息(使用 System.out.println),但我想在每个键/值对中执行一些操作(查找重复值,使用强制转换等比较值)

Map<String,String> l_map=new TreeMap<String,String>(); Map<String,String> l_map=new TreeMap<String,String>();

Thanks in advance!提前致谢!

You have to use for...each loop for iterate HashMap你必须使用for...each循环来迭代HashMap

Here down is example:下面是例子:

Map<String, String> map = new Map<String, String>;
// FILL DATA IN HASHMAP
 
for (Map.Entry<String, String> entry : map.entrySet()) {
    System.out.println(entry.getKey() + " " + entry.getValue());
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM