Here you can find the source of split(String str, String separator)
public static String[] split(String str, String separator)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static String[] split(String str, String separator) { String[] returnValue;/*ww w . j a v a 2s .c o m*/ int index = str.indexOf(separator); if (index == -1) { returnValue = new String[] { str }; } else { List<String> strList = new ArrayList<String>(); int oldIndex = 0; while (index != -1) { String subStr = str.substring(oldIndex, index); strList.add(subStr); oldIndex = index + separator.length(); index = str.indexOf(separator, oldIndex); } if (oldIndex != str.length()) { strList.add(str.substring(oldIndex)); } returnValue = strList.toArray(new String[strList.size()]); } return returnValue; } }