Sort the given string using character search | Java implementation to sort the given string without using any sorting technique ; function to sort the given string without using any sorting technique ; to store the final sorted string ; for each character ' i ' ; if character ' i ' is present at a particular index then add character ' i ' to ' new _ str ' ; required final sorted string ; Driver code
class GFG { static String sortString ( String str , int n ) { String new_str = " " ; for ( int i = ' a ' ; i <= ' z ' ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( str . charAt ( j ) == i ) new_str += str . charAt ( j ) ; return new_str ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int n = str . length ( ) ; System . out . print ( sortString ( str , n ) ) ; } }