Java Utililty Methods String Split

List of utility methods to do String Split

Description

The list of methods to do String Split are organized into topic(s).

Method

ListsplitIntegerPerDigit(int i)
split Integer Per Digit
List<Integer> digits = new ArrayList<Integer>();
while (i > 0) {
    digits.add(i % 10);
    i /= 10;
return digits;
String[]splitIntoPackages(String stmt)
split Into Packages
List pkgs = new ArrayList(2);
StringBuilder pkg = new StringBuilder();
boolean ignoreComma = false;
for (int stringIndex = 0; stringIndex < stmt.length(); stringIndex++) {
    char currentChar = stmt.charAt(stringIndex);
    if (currentChar == ',') {
        if (ignoreComma) {
            pkg.append(currentChar);
...
ListsplitIntoPairs(String subDirName)
splits the given subDirName into pairs of characters (odd length results in exception)
if (subDirName.length() % 2 == 1) {
    throw new IllegalArgumentException("subDirName contains an odd number of characters");
} else {
    List<String> ret = new ArrayList<>();
    int i = 0;
    while (i < subDirName.length()) {
        ret.add(subDirName.substring(i, i + 2));
        i = i + 2;
...
int[]splitInts(String str)
Parse comma-separated list of ints and return as array.
StringTokenizer tokenizer = new StringTokenizer(str, ",");
int n = tokenizer.countTokens();
int[] list = new int[n];
for (int i = 0; i < n; i++) {
    String token = tokenizer.nextToken();
    list[i] = Integer.parseInt(token);
return list;
...
ListsplitJsonObjects(String string)
split Json Objects
List<String> jsonObjects = new ArrayList<String>();
int brackets = 0;
int start = 0;
for (int i = 0; i < string.length(); i++) {
    switch (string.charAt(i)) {
    case '{':
        brackets++;
        if (brackets == 1)
...
String[]splitJsonObjects(String value)
split Json Objects
int openCurlies = 0;
List<String> objects = new ArrayList<String>();
StringBuilder object = new StringBuilder();
for (int i = 0; i < value.length(); i++) {
    char currentChar = value.charAt(i);
    object.append(currentChar);
    if (currentChar == '{') {
        openCurlies++;
...
ObjectsplitLargeStringIfNecessary(String s)
Utility for splitting strings into lists of strings to pass as arguments to VistA Remote Procedure Calls (RPCs) to work around LITERAL parameter length limitations in the RPC Broker protocol.
return splitLargeStringIfNecessary(s, 245);
ListsplitList(String list)
split List
return splitList(list, 0, list.length());
CollectionsplitList(String string)
split List
return string.length() == 0 ? Arrays.asList(new String[] {}) : Arrays.asList(string.split(";"));
ListsplitLists(String s)
Splits a parameter list thats encoded according to ISO 19143, 5.5
List<String> values = null;
if (s.startsWith("(")) {
    if (!s.endsWith(")")) {
        String msg = "KVP parameter list is not well-formed: '" + s + "'.";
        throw new IllegalArgumentException(msg);
    values = new ArrayList<String>();
    int pos = 1;
...