Java String Split by Char splitOnCharArray(String value, String splitOn)

Here you can find the source of splitOnCharArray(String value, String splitOn)

Description

split On Char Array

License

Open Source License

Declaration

public static String[] splitOnCharArray(String value, String splitOn) 

Method Source Code


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

import java.util.ArrayList;

public class Main {
    public static String[] splitOnCharArray(String value, String splitOn) {
        ArrayList<String> pointPairs = new ArrayList<String>();
        //Creating HashMap for faster search operation
        int i;/*w  ww .  ja v a 2s . c  o  m*/
        int prev = 0;
        for (i = 0; i < value.length(); i++) {
            if (splitOn.indexOf(value.charAt(i)) != -1) {
                pointPairs.add(value.substring(prev, i));
                while (i < value.length() && splitOn.indexOf(value.charAt(i)) != -1) {
                    i++;
                }
                prev = i;
                i--;
            }
        }
        boolean isLastElement = false;
        for (i = prev; i < value.length(); i++) {
            if (splitOn.indexOf(value.charAt(i)) == -1) {
                isLastElement = true;
                break;
            }
        }
        if (isLastElement) {
            pointPairs.add(value.substring(prev, value.length()));
        }
        return pointPairs.toArray(new String[0]);
    }
}

Related

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