Stores the frequency of the array elements
HashMap < Integer , Integer > mp1 = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > mp2 = new HashMap < Integer , Integer > ( ) ; for ( int x : A ) { if ( mp1 . containsKey ( x ) ) mp1 . put ( x , mp1 . get ( x ) + 1 ) ; else mp1 . put ( x , 1 ) ; } mp2 = ( HashMap < Integer , Integer > ) mp1 . clone ( ) ;