Remove odd indexed characters from a given string | Java program to implement the above approach ; Function to remove odd indexed characters from a given string ; Stores the resultant string ; If the current index is odd ; Skip the character ; Otherwise , append the character ; Return the modified string ; Driver Code ; Remove the characters which have odd index
import java . util . * ; class GFG { static String removeOddIndexCharacters ( String s ) { String new_string = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 1 ) continue ; new_string += s . charAt ( i ) ; } return new_string ; } public static void main ( String [ ] args ) { String str = " abcdef " ; str = removeOddIndexCharacters ( str ) ; System . out . print ( str ) ; } }