Here you can find the source of splitSimple(String split, String s)
s
into a List of Strings separated by split
, which is not a regex.
public static List splitSimple(String split, String s)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { /**// www . j a va 2 s . co m * Splits <code>s</code> into a List of Strings separated by <code>split</code>, * which is not a regex. This is more efficient than String.split or TextUtil.split * because it doesn't use a regex. */ public static List splitSimple(String split, String s) { return splitSimple(split, s, 4); } /** * Splits <code>s</code> into a List of Strings separated by <code>split</code>, * which is not a regex. This is more efficient than String.split or TextUtil.split * because it doesn't use a regex. * * @param expectedSize the expected size of the resulting list */ public static List splitSimple(String split, String s, int expectedSize) { if (split.length() == 0) throw new IllegalArgumentException(); List<String> result = new ArrayList<String>(expectedSize); int start = 0; int indexof; while ((indexof = s.indexOf(split, start)) != -1) { result.add(s.substring(start, indexof)); start = indexof + split.length(); if (start >= s.length()) break; } if (start == s.length()) { result.add(""); } else if (start < s.length()) { result.add(s.substring(start)); } return result; } }