java获取key,根据key遍历所有的集合value,然后遍历每个类目下的集合value代码
时间: 2023-06-04 18:08:45 浏览: 93
java集合类的代码
可以使用Java中的HashMap或者TreeMap来存储key-value对,然后使用keySet()方法获取所有的key,再通过循环遍历key,使用get(Object key)方法获取每个key对应的value,并进行处理即可。以下是示例代码:
HashMap<String, ArrayList<String>> map = new HashMap<>();
//put some key-value pairs into the map
//get all the keys and loop through them
for (String key : map.keySet()) {
//get the value associated with this key
ArrayList<String> values = map.get(key);
//iterate through the values and do some processing
for (String value : values) {
//do something with value
}
}
阅读全文