Java String Split by Char splitList(String source, char useChar)

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

Description

split List

License

Open Source License

Declaration

public static List splitList(String source, char useChar) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {

    public static List splitList(String source, char useChar) {
        List list = new ArrayList();
        String sub;// w ww  . j a v a 2  s.co m

        if (source.charAt(0) == useChar)
            source = source.substring(1, source.length());
        if (source.charAt(source.length() - 1) == useChar)
            source = source.substring(0, source.length() - 1);

        int start = 0;
        int end = source.indexOf(useChar);
        while (end > 0) {
            sub = source.substring(start, end);
            list.add(sub);
            start = end + 1;
            end = source.indexOf(useChar, start);
        }

        sub = source.substring(start, source.length());
        list.add(sub);

        return list;
    }
}

Related

  1. splitByNonNestedChars(String s, char... c)
  2. splitChars(String input, String charsToBeRemoved)
  3. splitEncolosed(String s, char open_tag, char close_tag)
  4. splitFast3(String data, char splitChar)
  5. splitInclusive(CharSequence input, char[] splitChars)
  6. splitOnChar(String str, char c)
  7. splitOnChar(String str, int ch)
  8. splitOnCharArray(String value, String splitOn)
  9. SplitSearchString(String search_string, char split_char, boolean clear_exact_match_char)