Here you can find the source of split(String token, String s)
public static String[] split(String token, String s)
//package com.java2s; /*/* w w w . j av a 2 s . c o m*/ * StringUtil.java * * Copyright (c) 2005-2009 Andrew Krizhanovsky <andrew.krizhanovsky at gmail.com> * Distributed under GNU Public License. */ import java.util.List; import java.util.ArrayList; public class Main { private final static String[] NULL_STRING_ARRAY = new String[0]; public static String[] split(String token, String s) { if (null == s || 0 == s.length()) return NULL_STRING_ARRAY; List<String> ls = new ArrayList<String>(); int previousLoc = 0; int loc = s.indexOf(token, previousLoc); if (-1 == loc) { ls.add(s); } else { do { ls.add(s.substring(previousLoc, loc)); previousLoc = (loc + token.length()); loc = s.indexOf(token, previousLoc); } while ((loc != -1) && (previousLoc < s.length())); ls.add(s.substring(previousLoc)); } return ((String[]) ls.toArray(NULL_STRING_ARRAY)); } }