Here you can find the source of split(String line, String separator)
public static String[] split(String line, String separator)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { public static String[] split(String line, String separator) { assertNotNull("line", line); assertNotNull("separator", separator); //if(separator.length() == 0) // throw new new("separator", separator, "May not be empty"); if (line.length() == 0) return new String[0]; int separatorLength = separator.length(); List list = new ArrayList(); int previousIndex = 0; for (int index = line.indexOf(separator); index != -1; index = line.indexOf(separator, previousIndex)) { list.add(line.substring(previousIndex, index)); previousIndex = index + separatorLength; }// w w w .j ava 2 s . com list.add(line.substring(previousIndex)); String stringArray[] = new String[list.size()]; list.toArray(stringArray); return stringArray; } private static void assertNotNull(String fieldName, Object object) { //if(object == null) // throw new DetailedNullPointerException(fieldName); //else return; } }