Skip to content

Instantly share code, notes, and snippets.

@edwardbeckett
Created December 10, 2014 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardbeckett/4e75f0aa2a110b1cc6e0 to your computer and use it in GitHub Desktop.
Save edwardbeckett/4e75f0aa2a110b1cc6e0 to your computer and use it in GitHub Desktop.
Counting Multiple Values in an Array... Java 8
package local;
import java.util.Arrays;
import java.util.stream.Collectors;
/**
* @author Edward Beckett :: <Edward@EdwardBeckett.com>
* @since :: 12/9/2014
*/
public class Multiples {
public static void main( String[] args ) {
Integer[] nums = { 1, 9, 999, 77, 77, 6, 88, 99, 99, 8, 999, 44, 3 };
Arrays.stream( nums )
.collect( Collectors.groupingBy( s -> s ) )
.forEach( ( k, v ) -> System.out.println( "Number: " + k + " Count: " + v.size() ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment