Yas*_*eni 2 java key hashmap multimap guava
我有以下方法:
public static void showStuff(Multimap<String, String> map) {
for (String key : map.keys()) {
System.out.println("The key, " + key
+ ", has the results: " + map.get(key));
}
}
Run Code Online (Sandbox Code Playgroud)
这输出:
The key, **one**, has the results: [a,b,c,d,d,e]
The key, **one**, has the results: [a,b,c,d,d,e]
The key, **one**, has the results: [a,b,c,d,d,e]
The key, **one**, has the results: [a,b,c,d,d,e]
The key, **one**, has the results: [a,b,c,d,d,e]
The key, **two**, has the results: [a,a,a,b,b,e]
The key, **two**, has the results: [a,a,a,b,b,e]
Run Code Online (Sandbox Code Playgroud)
我怎么才能输出唯一的密钥.我希望它只打印一次语句而不是多次重复它.我有一个表,其中不同的行具有重复键,因此我使用MultiMap获取重复键的所有值.我现在如何仅输出
The key, **one**, has the results: [a,b,c,d,d,e]
The key, **two**, has the results: [a,a,a,b,b,e]
Run Code Online (Sandbox Code Playgroud)
谢谢!
您可以使用Multimap.keySet()只获取不同的键.
您可以使用Multimap.entries()获取(键,值)对,而不必返回到映射以请求与每个键关联的值.
或者,您可以使用Multimap.asMap()它将其转换为a java.util.Map,然后使用它.
| 归档时间: |
|
| 查看次数: |
1138 次 |
| 最近记录: |