Java count occurrence of each element in an integer array
<p>I've written the following snippet to count the number of occurrences of each element. Is it possible to achieve this in a much shorter way?</p>

<pre><code>int[] arr = {1, 6, 2, 8, 5, 4, 7, 7, 5, 7};
Arrays.stream(arr)
        .collect(ArrayList::new, ArrayList::add, ArrayList::addAll)
        .stream()
        .collect(Collectors.groupingBy(s -&gt; s))
        .forEach((k, v) -&gt; System.out.println(k+" "+v.size()));
</code></pre>

<p>Also I would like to display only the elements which occur more than 1 time. So I tried modifying as below which resulted in an error. </p>

<pre><code>.forEach((k, v) -&gt; if(v.size() &gt; 1) System.out.println(k+" "+v.size()));
</code></pre>

<p>What is the correct way to do this?</p>