我对Java 8的新特性还不太熟悉。我正在学习如何按条目过滤地图。我已经查看了这篇教程和这个帖子来解决我的问题,但是我无法解决。
@Test
public void testSomething() throws Exception {
HashMap<String, Integer> map = new HashMap<>();
map.put("1", 1);
map.put("2", 2);
map = map.entrySet()
.parallelStream()
.filter(e -> e.getValue()>1)
.collect(Collectors.toMap(e->e.getKey(), e->e.getValue()));
}
然而,我的IDE(IntelliJ)显示“无法解析方法'getKey()'”,因此无法编译:
这也没有帮助:
有人能帮我解决这个问题吗?
谢谢。