Here you can find the source of tokenize(String s)
public static String[] tokenize(String s)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /** Tokenize string s into an array */ public static String[] tokenize(String s) { ArrayList<String> r = new ArrayList<String>(); String remain = s;//ww w .j a v a2 s . com int n = 0, pos; remain = remain.trim(); while (remain.length() > 0) { if (remain.startsWith("\"")) { // Field in quotes pos = remain.indexOf('"', 1); if (pos == -1) break; r.add(remain.substring(1, pos)); if (pos + 1 < remain.length()) pos++; } else { // Space-separated field pos = remain.indexOf(' ', 0); if (pos == -1) { r.add(remain); remain = ""; } else r.add(remain.substring(0, pos)); } remain = remain.substring(pos + 1); remain = remain.trim(); // - is used as a placeholder for empy fields if (r.get(n).equals("-")) r.set(n, ""); n++; } return r.toArray(new String[0]); } }