我得到以下Multimap
,我怎麼能把它轉換成MultiMap<String,Integer>
?如何將MultiMap <String,String>轉換爲MultiMap <String,Integer>?
Multimap<String, String> multimap= // contents here
我得到以下Multimap
,我怎麼能把它轉換成MultiMap<String,Integer>
?如何將MultiMap <String,String>轉換爲MultiMap <String,Integer>?
Multimap<String, String> multimap= // contents here
一種方式是通過所有的值在第一張地圖和他們使用String.parseInt(),然後將它們添加到一個新的地圖。
使用Multimaps#transformValues(Multimap, Function)
:
Multimap<String, Integer> transformed = Multimaps.transformValues(multimap,
new Function<String, Integer>() {
@Override public Integer apply(String value) {
return Integer.valueOf(value);
}
});
參見:
感謝材料。 – Njax3SmmM2x2a0Zf7Hpd
@Macon爲什麼你沒有接受和解決問題呢? – Xaerxess
[你嘗試過什麼(HTTP://米attgemmell.com/2008/12/08/what-have-you-tried/)? –
發佈問題之前,您是否閱讀過文檔?項目頁面上也有一個很好的[覆蓋此主題的Wiki](https://code.google.com/p/guava-libraries/wiki/NewCollectionTypesExplained#Multimap)。 – Xaerxess
@Xaerxess是啊,但可悲的是它沒有提到如何轉換條目 – Njax3SmmM2x2a0Zf7Hpd