Skip to content

Instantly share code, notes, and snippets.

@asela38
Created July 31, 2018 10:03
Show Gist options
  • Save asela38/934ad83bdb8999da85100c870095cea5 to your computer and use it in GitHub Desktop.
Save asela38/934ad83bdb8999da85100c870095cea5 to your computer and use it in GitHub Desktop.

To Find Highest Frequency number with the frequency following code can be use quite nicely

    @Test
    public void findHighestFrequency() throws Exception {

        Stream.of(1,2,2,1,2,1,2,2,1,2,1,2,2,1,2,1,2,2,1,2,1,2,2,1,2)
                .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
                .entrySet().stream()
                .max((a,b) -> a.getValue().compareTo(b.getValue()))
                .ifPresent(System.out::println);

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment