Here you can find the source of split(String s, String separator)
public static List<String> split(String s, String separator)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.List; public class Main { public static List<String> split(String s, String separator) { List<String> result = new ArrayList<>(); int lastIndex = 0; int index = s.indexOf(separator); while (index != -1) { String substring = s.substring(lastIndex, index); if (!substring.equals(separator) && index > 0) result.add(substring);/*from w w w. j a va 2 s .co m*/ lastIndex = index + separator.length(); index = s.indexOf(separator, lastIndex); } if (lastIndex < s.length()) result.add(s.substring(lastIndex, s.length())); return result; } }