Java 8 Lambda, filter HashMap, cannot resolve method

后端 未结 2 1070
忘了有多久
忘了有多久 2021-02-07 02:32

I\'m kinda new to Java 8\'s new features. I am learning how to filter a map by entries. I have looked at this tutorial and this post for my problem, but I am unable to solve.

2条回答
  •  遥遥无期
    2021-02-07 02:52

    The message is misleading but your code does not compile for another reason: collect returns a Map not a HashMap.

    If you use

    Map map = new HashMap<>();
    

    it should work as expected (also make sure you have all the relevant imports).

提交回复
热议问题