Here you can find the source of split(String str, char separatorChar, boolean preserveAllTokens)
public static String[] split(String str, char separatorChar, boolean preserveAllTokens)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { private static String[] EMPTY_STRING_ARRAY = new String[0]; public static String[] split(String str, char separatorChar, boolean preserveAllTokens) { // Performance tuned for 2.0 (JDK1.4) if (str == null) { return null; }// w w w.ja v a2s . c o m int len = str.length(); if (len == 0) { return EMPTY_STRING_ARRAY; } List<String> list = new ArrayList<String>(); int i = 0, start = 0; boolean match = false; boolean lastMatch = false; while (i < len) { if (str.charAt(i) == separatorChar) { if (match || preserveAllTokens) { list.add(str.substring(start, i)); match = false; lastMatch = true; } start = ++i; continue; } lastMatch = false; match = true; i++; } if (match || (preserveAllTokens && lastMatch)) { list.add(str.substring(start, i)); } return (String[]) list.toArray(new String[list.size()]); } }