2016-07-28 46 views
-1

我是新來的Java 8,我有麻煩纏繞我的頭圍繞如何得到這個數據到地圖 -的Java 8 toMap的地圖<字符串,收藏<String>>

我讀出從配置文件中的數據 - 它看起來是這樣的(例子) -

SomeName = { 
    someAttribute = "attributeVal", 
    someImportantAttributeList = ("val1", "val2", "val3"), 
    ... 
} 

SomeName2 = { 
    someAttribute .... 
} 

... 

我試圖將數據收集到一張地圖,這樣的地圖是地圖W /鍵值爲SomeName和作爲字符串集合的值(「someImportantAttributeList」。)

其他所有d阿塔無所謂。

現在,我有這樣的事情:

Map<String, Collection<String>> mapping = configReader.getConfig() 
    .entrySet() 
    .stream() 
    .filter(entry -> entry.getValue().containsKey("someImportantAttributeList") 
    . ???? 

我無法搞清楚如何正確地得到這個映射到一個字符串,收藏地圖?

流本身似乎是其值爲Key = SomeName,value = String/Object類型的內部映射的條目。 (所以在這種情況下,進入的主要是SomeName,該值將字符串鍵(someAttribute)和對象值(即屬性的值)的另一種映射。

任何幫助將不勝感激!

+0

from [documentation](http://stackoverflow.com/documentation/java/88/streams/909/creating-a-frequency-map#t=2016072817494356061) – Andrew

回答

1
.collect(Collectors.toMap(Entry::getKey, entry -> 
(Collection<String>) entry.getValue().get("someImportantAttributeList"))); 
相關問題