Here you can find the source of split(String str, int ch)
public static List<String> split(String str, int ch)
//package com.java2s; import java.util.*; public class Main { public static List<String> split(String str, int ch) { int begin = 0; for (; begin < str.length(); begin++) { if (str.charAt(begin) != ch) { break; }//from www.j a va 2s . com } if (begin > 0) { str = str.substring(begin); begin = 0; } int idx = str.indexOf(ch); if (idx == -1) { return Arrays.asList(str.trim()); } else { ArrayList<String> strs = new ArrayList<String>(2); while (idx > -1) { String s = str.substring(begin, idx).trim(); if (s.length() > 0) { strs.add(s); } begin = idx + 1; idx = str.indexOf(ch, begin); } String s = str.substring(begin).trim(); if (s.length() > 0) { strs.add(s); } return strs; } } }