[英]How to get all list from a hashtable by keyset
@Test
public void mich() {
Hashtable<String,List<Path>> mct = new Hashtable<String,List<Path>>();
List<Path> mm = Arrays.asList(Paths.get("File1"), Paths.get("File2"), Paths.get("File3"));
List<Path> bb = Arrays.asList(Paths.get("File4"), Paths.get("File5"), Paths.get("File6"));
List<Path> dd = Arrays.asList(Paths.get("File7"), Paths.get("File8"), Paths.get("File9"));
mct.put("A",mm);
mct.put("B",bb);
mct.put("C",dd);
List<Path> result = mct.keySet().stream().filter(s -> !s.equalIgnoreCase("C")).peek(System.out::println).map(s -> mct.get(s)).collect(Collectors.toList());
}
我想要我的結果
File1
File2
File3
File4
File5
File6
如何映射我的路徑列表?
而不是keySet
你必須使用entrySet
因為你使用兩個鍵和值來過濾鍵和獲取Paths的值,你也必須像這樣使用flatMap :
List<Path> result = mct.entrySet().stream()
.filter(e -> !"C".equalsIgnoreCase(e.getKey()))
.flatMap(e -> e.values().stream())
.collect(Collectors.toList());
result.forEach(p -> System.out.println(p.getFileName()));
輸出
File1
File2
File3
File4
File5
File6
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.