Function to move all the alphabets to front
static String removeChars ( String hexaVal , String S ) { HashSet < Character > setk = new HashSet < > ( ) ; for ( char ch : S . toCharArray ( ) ) { setk . add ( ch ) ; } String ans = " " ; for ( char ch : hexaVal . toCharArray ( ) ) { if ( setk . contains ( ch ) ) { continue ; } ans += ch ; } return ans ; }