Java - Write code to tokenize a string with Comma

Requirements

Write code to tokenize a string with Comma

Demo

//package com.book2s;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s,com";
        System.out.println(java.util.Arrays
                .toString(getFromCommaSeparated(str)));
    }//from   w w  w  .  j a  v a  2 s  .  co  m

    public static String[] getFromCommaSeparated(String str) {
        StringTokenizer tokenizer = new StringTokenizer(str, ",");
        int count = tokenizer.countTokens();

        String[] array = new String[count];
        for (int i = 0; i < count; i++) {
            array[i] = tokenizer.nextToken();
        }

        return array;
    }
}