public static < T extends Number > T mode ( Collection < T > values ) { if ( values . isEmpty ( ) ) throw new IllegalArgumentException ( "No mode in an empty collection" ) ; Counter < T > c = new ObjectCounter < T > ( ) ; for ( T n : values ) c . count ( n ) ; return c . max ( ) ; }
Returns the mode value of the collection of numbers