Java - Write code to split a string by a delimiter using StringTokenizer

Requirements

Write code to split a string

Demo

//package com.book2s;

import java.util.ArrayList;

import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        String delimiters = ".";
        System.out.println(java.util.Arrays
                .toString(split(str, delimiters)));
    }//from  www .j a  v  a2s  . c  o  m

    public static String[] split(String str, String delimiters) {
        final StringTokenizer st = new StringTokenizer(str, delimiters);
        final List<String> tokens = new ArrayList<String>();
        while (st.hasMoreTokens()) {
            final String token = st.nextToken();
            tokens.add(token);
        }
        return tokens.toArray(new String[tokens.size()]);
    }

}