Java tutorial
//package com.java2s; import java.util.ArrayList; public class Main { public static String[] splitByWhitespace(String str) { ArrayList<String> list = new ArrayList<String>(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (ch == ' ' || ch == '\t') { if (buf.length() > 0) { list.add(buf.toString()); buf = new StringBuilder(); } } else { buf.append(ch); } } if (buf.length() > 0) list.add(buf.toString()); return list.toArray(new String[list.size()]); } }