Modify the string such that every character gets replaced with the next character in the keyboard | Java implementation of the approach ; Function to return the modified String ; Map to store the next character on the keyboard for every possible lowercase character ; Update the String ; Driver code
import java . util . * ; class GFG { static String CHARS = " qwertyuiopasdfghjklzxcvbnm " ; static int MAX = 26 ; static String getString ( char [ ] str , int n ) { Map < Character , Character > uMap = new HashMap < > ( ) ; for ( int i = 0 ; i < MAX ; i ++ ) { uMap . put ( CHARS . charAt ( i ) , CHARS . charAt ( ( i + 1 ) % MAX ) ) ; } for ( int i = 0 ; i < n ; i ++ ) { str [ i ] = uMap . get ( str [ i ] ) ; } return String . valueOf ( str ) ; } public static void main ( String [ ] args ) { String str = " geeks " ; int n = str . length ( ) ; System . out . println ( getString ( str . toCharArray ( ) , n ) ) ; } }