Java String Split by Char splitOnChar(String str, char c)

Here you can find the source of splitOnChar(String str, char c)

Description

split On Char

License

Open Source License

Declaration

public static String[] splitOnChar(String str, char c) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;

public class Main {
    public static String[] splitOnChar(String str, char c) {
        ArrayList<String> result = new ArrayList<String>();

        int lastOffset = 0;
        int curOffset;
        while ((curOffset = str.indexOf(c, lastOffset)) != -1) {
            result.add(str.substring(lastOffset, curOffset));
            lastOffset = curOffset + 1;/*from  w  w w. j  a  v a 2 s .  c  om*/
        }

        result.add(str.substring(lastOffset));

        return result.toArray(new String[result.size()]);
    }
}

Related

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