// Ivan Novick // Feb 18, 2008 // split on whitespace ... like using awk class splitws { public static void main(String args[]) { String input = "This string contains both tabs and spaces"; // split on white space String tokens[] = input.split("\\s+"); // iterate through the generated array of tokens for (int i = 0; i < tokens.length ; ++i) { System.out.println("Token #" + (i+1) + ": " + tokens[i] + "."); } } }