Java Data Type How to - Divide a sentence into parts


We would like to know how to divide a sentence into parts.


import java.util.StringTokenizer;
/*from  ww  w .  jav  a2s .  c o m*/
public class Main {

  private static String[] tokenize(String str) {
    StringTokenizer tokenizer = new StringTokenizer(str);
    String[] arr = new String[tokenizer.countTokens()];
    int i = 0;
    while (tokenizer.hasMoreTokens()) {
      arr[i++] = tokenizer.nextToken();
    return arr;

  public static void main(String[] args) {
    String[] strs = tokenize("this is a test");
    for (String s : strs)