Mode of frequencies of given array elements | Java program of the above approach ; Function to find the mode of the frequency of the array ; Stores the frequencies of array elements ; Traverse through array elements and count frequencies ; Stores the frequencies 's of  frequencies of array elements ; Stores the minimum value ; Find the Mode in 2 nd map ; Search for this Mode ; When mode is find then return to main function . ; If mode is not found ; Driver Code
import java . util . * ; class GFG { static int countFreq ( int arr [ ] , int n ) { HashMap < Integer , Integer > mp1 = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp1 . containsKey ( arr [ i ] ) ) { mp1 . put ( arr [ i ] , mp1 . get ( arr [ i ] ) + 1 ) ; } else { mp1 . put ( arr [ i ] , 1 ) ; } } HashMap < Integer , Integer > mp2 = new HashMap < Integer , Integer > ( ) ; for ( Map . Entry < Integer , Integer > it : mp1 . entrySet ( ) ) { if ( mp2 . containsKey ( it . getValue ( ) ) ) { mp2 . put ( it . getValue ( ) , mp2 . get ( it . getValue ( ) ) + 1 ) ; } else { mp2 . put ( it . getValue ( ) , 1 ) ; } } int M = Integer . MIN_VALUE ; for ( Map . Entry < Integer , Integer > it : mp2 . entrySet ( ) ) { M = Math . max ( M , it . getValue ( ) ) ; } for ( Map . Entry < Integer , Integer > it : mp2 . entrySet ( ) ) { if ( M == it . getValue ( ) ) { return it . getKey ( ) ; } } return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 10 , 3 , 10 , 8 , 3 , 6 , 4 } ; int n = arr . length ; System . out . print ( countFreq ( arr , n ) ) ; } }