/* A StringTokenizer example: given a list of elements, return the first element and the list of all but the first element (i.e. the rest of the list). */ import java.util.Scanner; import java.util.StringTokenizer; class First_Rest { public static void main (String[] args) { Scanner scan = new Scanner(System.in); StringTokenizer list; String new_list = ""; String next_word; System.out.print ("Enter a list of words: "); System.out.flush(); list = new StringTokenizer (scan.nextLine()); System.out.println ("The first element of the list is: " + list.nextToken()); while (list.hasMoreTokens()) { next_word = list.nextToken(); new_list = new_list.concat(next_word); new_list = new_list.concat(" "); } System.out.println ("The rest of the list is: " + new_list); } }