Here you can find the source of splitString(String s)
public static String[] splitString(String s)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public final static String CRLF = "" + (char) 13 + (char) 10; public static String[] splitString(String s) { if (s == null) return new String[0]; ArrayList<String> ret = new ArrayList<String>(); int pos = 0; while (true) { int end = findNext(s, CRLF, pos); if (end < 0) { ret.add(s.substring(pos)); break; } else { int len = end - pos; if (len > 0) { ret.add(s.substring(pos, end)); }// www . j av a 2 s. c o m pos = end + 1; } } return ret.toArray(new String[ret.size()]); } public static String[] splitString(String s, char c) { if (s == null) return new String[0]; ArrayList<String> ret = new ArrayList<String>(); int pos = 0; while (true) { int end = s.indexOf(s, pos); if (end < 0) { ret.add(s.substring(pos)); break; } else { int len = end - pos; if (len > 0) { ret.add(s.substring(pos, end)); } pos = end + 1; } } return ret.toArray(new String[ret.size()]); } public static int findNext(String s, String chars, int fromIndex) { int p = Integer.MAX_VALUE; for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); int p2 = s.indexOf(c, fromIndex); if (p2 < 0) continue; if (p2 < p) p = p2; } if (p == Integer.MAX_VALUE) return -1; else return p; } }