Occurences of a number using streams in Java

I have an integer list containing some duplicate numbers. How can I count the occurences of a specific number in that list using streams?

  List<Integer> newList = new ArrayList<>();

        newList.add(3);
        newList.add(6);
        newList.add(6);
        newList.add(6);
        newList.add(4);
        newList.add(9);
        newList.add(0);

For instance, for the number 6 I would like to return 3.



Read more here: https://stackoverflow.com/questions/68467485/occurences-of-a-number-using-streams-in-java

Content Attribution

This content was originally published by classicmusiclover at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: