Java String Split by Comma splitCommaSequence(String argumentString)

Here you can find the source of splitCommaSequence(String argumentString)

Description

split Comma Sequence

License

Apache License

Declaration

public static ArrayList<String> splitCommaSequence(String argumentString) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> splitCommaSequence(String argumentString) {
        ArrayList<String> arguments = new ArrayList<String>();
        int parCount = 0;
        int lastBeginIndex = 0;

        for (int i = 1; i < argumentString.length(); i++) {
            if (argumentString.charAt(i) == '(')
                parCount++;// w  w  w  .ja va2 s  .c  o  m
            if (argumentString.charAt(i) == ')')
                parCount--;
            if (argumentString.charAt(i) == ',' && parCount == 0) {
                arguments.add(argumentString.substring(lastBeginIndex, i));
                lastBeginIndex = i + 1;
            }
        }
        String toAdd = argumentString.substring(lastBeginIndex, argumentString.length());
        if (toAdd.length() != 0 && !toAdd.matches("/^\\s*$/")) {
            arguments.add(toAdd);
        }

        return arguments;

    }
}

Related

  1. splitComma(String configValue)
  2. splitCommand(String command)
  3. splitCommand(String command)
  4. splitCommand(String command)
  5. splitCommandString(String command_string)
  6. splitCommaStr(String commaStr)
  7. splitDoubleParentCommas(String input)
  8. splitOnComma(String cs)
  9. splitWithCommaOrSemicolon(String src)