Change string to a new character set | Java program to change the sentence with virtual dictionary ; Converts str to given character set ; hashing for new character set ; conversion of new character set ; Driver code
class GFG { static String conversion ( char charSet [ ] , String str ) { int n = str . length ( ) ; char hashChar [ ] = new char [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { int ch = Math . abs ( charSet [ i ] - ' a ' ) ; hashChar [ ch ] = ( char ) ( ' a ' + i ) ; } String s = " " ; for ( int i = 0 ; i < n ; i ++ ) { s += hashChar [ str . charAt ( i ) - ' a ' ] ; } return s ; } public static void main ( String [ ] args ) { char charSet [ ] = " qwertyuiopasdfghjklzxcvbnm " . toCharArray ( ) ; String str = " egrt " ; str = conversion ( charSet , str ) ; System . out . println ( str ) ; } }