Java String Split by Separator splitList(String source, char separator)

Here you can find the source of splitList(String source, char separator)

Description

split List

License

Open Source License

Declaration

public static List<String> splitList(String source, char separator) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> splitList(String source, char separator) {
        return splitList(source, separator, false, null);
    }/*from w w w  .  ja v  a2s .  c  om*/

    public static List<String> splitList(String source, char separator,
            boolean trim) {
        return splitList(source, separator, trim, null);
    }

    public static List<String> splitList(String source, char separator,
            boolean trim, List<String> output) {
        return splitList(source, Character.toString(separator), trim,
                output);
    }

    public static List<String> splitList(String source, String separator) {
        return splitList(source, separator, false, null);
    }

    public static List<String> splitList(String source, String separator,
            boolean trim) {
        return splitList(source, separator, trim, null);
    }

    public static List<String> splitList(String source, String separator,
            boolean trim, List<String> output) {
        if (output == null)
            output = new ArrayList<String>();
        if (source.length() == 0)
            return output;
        int pos = 0;
        do {
            int npos = source.indexOf(separator, pos);
            if (npos < 0)
                npos = source.length();
            String piece = source.substring(pos, npos);
            if (trim)
                piece = piece.trim();
            output.add(piece);
            pos = npos + 1;
        } while (pos < source.length());
        return output;
    }
}

Related

  1. splitBySeparator(String path, String separator)
  2. splitByStringSeparator(String theString, String separatorString)
  3. splitDoubles(String str, String fieldSeparator)
  4. splitField(String fieldWithSeparator, String separator)
  5. splitInts(String string, String separator)
  6. splitListBySeparator(String text, String separator)
  7. splitNotRegex(String str, String separatorChars)
  8. splitSmart(String s, char separator)
  9. splitStaySeparator(String str, char token)