Here you can find the source of split(String string)
public static String[] split(String string)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static String[] split(String string) { String s = string;/*from w ww.j a va 2s . c om*/ if (s != null) s = s.trim(); String[] sArr = s.split("([ \t])+"); List<String> list = new ArrayList<String>(); boolean insideQuote = false; String tmp = null; for (int i = 0; i < sArr.length; i++) { if (!insideQuote && sArr[i].indexOf("\"") == -1) list.add(sArr[i]); else if (!insideQuote && sArr[i].startsWith("\"")) { insideQuote = true; tmp = sArr[i].substring(1); if (tmp.endsWith("\"")) { insideQuote = false; tmp = tmp.substring(0, tmp.length() - 1); list.add(tmp); tmp = null; } } else if (insideQuote && sArr[i].endsWith("\"")) { insideQuote = false; tmp += " " + sArr[i].substring(0, sArr[i].length() - 1); list.add(tmp); tmp = null; } else { //insideQuote && !sArr[i].endsWith("\"") tmp += " " + sArr[i]; } } String[] retArr = new String[list.size()]; for (int i = 0; i < list.size(); i++) { retArr[i] = list.get(i); } return retArr; } }