Change string to a new character set | Java program to change the sentence with virtual dictionary ; function for converting the string ; find the index of each element of the string in the modified set of alphabets replace the element with the one having the same index in the actual set of alphabets ; Driver Code
class GFG { static char [ ] alphabets = " abcdefghijklmnopqrstuvwxyz " . toCharArray ( ) ; static String conversion ( String charSet , char [ ] str1 ) { String s2 = " " ; for ( char i : str1 ) s2 += alphabets [ charSet . indexOf ( i ) ] ; return s2 ; } public static void main ( String [ ] args ) { String charSet = " qwertyuiopasdfghjklzxcvbnm " ; String str1 = " egrt " ; System . out . print ( conversion ( charSet , str1 . toCharArray ( ) ) ) ; } }