Kth space | Java program of the above approach ; Function to extract integer at key position in the given String ; StringTokenizer ( ) : Extracts the number at key c_str ( ) : Type cast String to char * ; Driver Code ; Given String ; Given K ; Function call
import java . util . * ; class GFG { static void print_kth_String ( String str , int K ) { StringTokenizer st = new StringTokenizer ( str ) ; int count = 1 ; while ( st . hasMoreTokens ( ) && K > 0 ) { if ( count == K ) System . out . println ( st . nextToken ( ) ) ; count ++ ; st . nextToken ( ) ; } } public static void main ( String [ ] args ) { String s = ( "10 ▁ 20 ▁ 30 ▁ 40" ) ; int K = 2 ; print_kth_String ( s , K ) ; } }