Java String Split splitSimple(String split, String s)

Here you can find the source of splitSimple(String split, String s)

Description

Splits s into a List of Strings separated by split, which is not a regex.

License

Open Source License

Declaration

public static List splitSimple(String split, String s) 

Method Source Code


//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;
    }
}

Related

  1. SplitSearchTerms(String strSearch)
  2. splitSelection(String selection)
  3. splitSelectionAsInteger(String selection)
  4. splitSemicolonString(String semicolonString)
  5. splitSentence(String sentence)
  6. splitSimpleQueries(String queryString)
  7. splitSQL(List list, String sql)
  8. splitSQLColumns(String sql)
  9. splitStep(String step)