If X is not found
if ( ! st . contains ( x ) ) return " Invalid " ; } Arrays . sort ( s , new Comparator < Character > ( ) { @ Override public int compare ( Character x , Character y ) { return charVal ( y ) - charVal ( x ) ; } } ) ; String ss = " " ; for ( char ch : s ) ss += ch ;