Here you can find the source of split(String value, char delim)
public static String[] split(String value, char delim)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { private static final String EMPTY_STRING = ""; /**/* ww w . j a va 2 s. c o m*/ * Splits the specified {@link String} with the specified delimiter. This * operation is a simplified and optimized version of * {@link String#split(String)}. */ public static String[] split(String value, char delim) { final int end = value.length(); final List<String> res = new ArrayList<String>(); int start = 0; for (int i = 0; i < end; i++) { if (value.charAt(i) == delim) { if (start == i) { res.add(EMPTY_STRING); } else { res.add(value.substring(start, i)); } start = i + 1; } } if (start == 0) { // If no delimiter was found in the value res.add(value); } else { if (start != end) { // Add the last element if it's not empty. res.add(value.substring(start, end)); } else { // Truncate trailing empty elements. for (int i = res.size() - 1; i >= 0; i--) { if (res.get(i).isEmpty()) { res.remove(i); } else { break; } } } } return res.toArray(new String[res.size()]); } }