Creating a HashMap containing char as a key and occurrences as a value
HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int x : arr ) { if ( map . containsKey ( x ) ) map . put ( x , map . get ( x ) + 1 ) ; else map . put ( x , 1 ) ; }