Usage of String tokenizer

How to use space as a delimiter in StringTokenizer(Java)

Space is the default delimiter!!

StringTokenizer st = new StringTokenizer(string); would do.

You can also use the more generic constructor.

StringTokenizer st = new StringTokenizer(string, " ");

Here, the second parameter is a string, each character of which will act as a delimiter. So, to delimit using spaces as well as commas and periods, you could use new StringTokenizer(string, " .,");

Note that “string” is the string which we want to tokenize.

If the second parameter is missing, it takes spaces (the space character, the tab character, the newline character, the carriage-return character, and the form-feed character) by default. That is, new StringTokenizer(string); is equivalent to new StringTokenizer(string, " \t\n\r\f");

For more information, you can refer to Javadoc here.