Here you can find the source of split(String str, char separator)
public static String[] split(String str, char separator)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { public static String[] split(String str, char separator) { // String.split returns a single empty result for splitting the empty // string. if (str.isEmpty()) { return new String[] { "" }; }// w w w .jav a 2 s . co m ArrayList<String> strList = new ArrayList<>(); int startIndex = 0; int nextIndex = 0; while ((nextIndex = str.indexOf(separator, startIndex)) != -1) { strList.add(str.substring(startIndex, nextIndex)); startIndex = nextIndex + 1; } strList.add(str.substring(startIndex)); // remove trailing empty split(s) int last = strList.size(); // last split while (--last >= 0 && "".equals(strList.get(last))) { strList.remove(last); } return strList.toArray(new String[strList.size()]); } }