Java 8 frequency Object in array [duplicate]

佐手、 提交于 2019-12-01 08:52:51

You can do (I hope I don't have any typos) :

Map<Object,Long> map = Stream.of(array)
                                .collect(Collectors.groupingBy(o -> o,
                                                               Collectors.counting()));

This should group the elements of the array by equality and count the number of Objects in each group.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!