To store the frequency of characters of String str3
HashMap < Character , Integer > freq = new HashMap < > ( ) ; for ( int i = 0 ; i < str3 . length ( ) ; i ++ ) { if ( freq . containsKey ( str3 . charAt ( i ) ) ) freq . put ( str3 . charAt ( i ) , freq . get ( str3 . charAt ( i ) ) + 1 ) ; else freq . put ( str3 . charAt ( i ) , 1 ) ; }