Here you can find the source of split(String str, char ch)
public static String[] split(String str, char ch)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; public class Main { public static final String[] EMPTY_STRING_ARRAY = new String[0]; public static String[] split(String str, char ch) { ArrayList list = null;//from w w w.jav a 2 s . co m int ix = 0; int len = str.length(); for (int i = 0; i < len; ++i) { char c = str.charAt(i); if (c == ch) { if (list == null) { list = new ArrayList(); } list.add(str.substring(ix, i)); ix = i + 1; } } if (ix > 0) { list.add(str.substring(ix)); } return list == null ? EMPTY_STRING_ARRAY : (String[]) ((String[]) list.toArray(EMPTY_STRING_ARRAY)); } }