Here you can find the source of split(String strSource, String strReg)
public static String[] split(String strSource, String strReg)
//package com.java2s; import java.util.*; public class Main { public static String[] split(String strSource, String strReg) { if (strSource == null) return null; if (strReg == null || strReg.equals("")) return new String[] { strSource }; ArrayList arrLst = new ArrayList(); splitA(strSource, strReg, arrLst); String arrRslt[] = new String[arrLst.size()]; return (String[]) arrLst.toArray(arrRslt); }//from ww w . ja v a2s . c o m private static void splitA(String strSource, String strReg, ArrayList arrLst) { int iFind = strSource.indexOf(strReg); if (iFind == -1) { arrLst.add(strSource); // return strSource; return; } int nRegLen = strReg.length(); int nSourceLen = strSource.length(); arrLst.add(strSource.substring(0, iFind)); splitA(strSource.substring(iFind + nRegLen, nSourceLen), strReg, arrLst); } }