Here you can find the source of split(String strToSplit, String strSeparator, int iLimit)
public static String[] split(String strToSplit, String strSeparator, int iLimit)
//package com.java2s; //License from project: Open Source License public class Main { public static String[] split(String strToSplit, String strSeparator, int iLimit) { java.util.ArrayList tmpList = new java.util.ArrayList(); int iFromIndex = 0; int iCurIndex = strToSplit.length(); String strUnitInfo = ""; int iCurCounts = 0; while ((iCurIndex != -1) && (iFromIndex <= strToSplit.length()) && (iCurCounts < iLimit)) { iCurIndex = strToSplit.indexOf(strSeparator, iFromIndex); if (iCurIndex == -1) { strUnitInfo = strToSplit.substring(iFromIndex, strToSplit.length()); } else { strUnitInfo = strToSplit.substring(iFromIndex, iCurIndex); iFromIndex = iCurIndex + strSeparator.length(); }// ww w . jav a2 s. c o m tmpList.add(strUnitInfo); iCurCounts++; } int iCounts = tmpList.size(); String tmpArray[] = new String[iCounts]; for (int i = 0; i < iCounts; i++) { tmpArray[i] = (String) tmpList.get(i); } return tmpArray; } }