Here you can find the source of split(String s, String splitter)
public static String[] split(String s, String splitter)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static String[] split(String s, String splitter) { if (s == null) { throw new IllegalArgumentException( "The string to be splitted cannot be null"); }/*from ww w . ja va 2 s .c om*/ if (splitter == null || splitter.length() == 0) { throw new IllegalArgumentException( "The string splitter cannot be empty"); } List<String> parts = new ArrayList<>(); int n = splitter.length(); int i = 0; int j = s.indexOf(splitter); while (j != -1) { parts.add(s.substring(i, j)); i = j + n; j = s.indexOf(splitter, i); } parts.add(s.substring(i)); return parts.toArray(new String[parts.size()]); } }