Java String Split recursiveSplit(String str, String splitor)

Here you can find the source of recursiveSplit(String str, String splitor)

Description

recursive Split

License

Apache License

Declaration

public static List<String> recursiveSplit(String str, String splitor) 

Method Source Code

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

import java.util.ArrayList;
import java.util.List;

public class Main {

    public static List<String> recursiveSplit(String str, String splitor) {
        List<String> re = new ArrayList<String>();
        String[] strs = twoPartSplit(str, splitor);
        if (strs.length == 2) {
            re.add(strs[0]);// ww  w .j av a2  s.c o  m
            re.addAll(recursiveSplit(strs[1], splitor));
        } else {
            re.add(strs[0]);
        }
        return re;
    }

    public static String[] twoPartSplit(String str, String splitor) {
        if (str != null && splitor != null) {
            int index = str.indexOf(splitor);
            if (index != -1) {
                String first = str.substring(0, index);
                String sec = str.substring(index + splitor.length());
                return new String[] { first, sec };
            } else {
                return new String[] { str };
            }
        } else {
            return new String[] { str };
        }
    }
}

Related

  1. getInputs(String str)
  2. getParameters(String[] split)
  3. getUsedInputs(String expression)
  4. safeSplitParameters(String parameters)
  5. split(byte[] bytes, byte[] p)
  6. split(byte[] data)
  7. split(byte[] input)