![](/img/trans.png)
[英]How Can we show One Key and its Values from Map<String, List<Object>> at a time on a JSP page?
[英]How to save map<String,list<String>> to another map of same type by self checking the values for its key's value
快速而骯臟的解決方案:
Map<String, List<String>> sndMap = new Map<String, List<String>>();
// Go throuch first map and copy all keys to second map
for (String key : firstMap.keySet()) {
if (!sndMap.containsKey(key)) {
sndMap.put(key, new List<String>());
}
List<String> tmp = sndMap.get(key);
tmp.add(firstMap.get(key).get(0));
sndMap.put(key, tmp);
}
// Go throuch all List of values in first map and check if a value is a key in the second map.
for (List<String> values : firstMap.values()) {
for (String s : values) {
if (sndMap.containsKey(s)) {
List<String> tmpList = sndMap.get(s);
tmpList.add(s);
sndMap.put(s, tmpList);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.