Created
December 10, 2014 02:24
-
-
Save edwardbeckett/4e75f0aa2a110b1cc6e0 to your computer and use it in GitHub Desktop.
Counting Multiple Values in an Array... Java 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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