Java String Split by Delimiter splitByStr(String s, String delim)

Here you can find the source of splitByStr(String s, String delim)

Description

split By Str

License

Apache License

Declaration

public static List<String> splitByStr(String s, String delim) 

Method Source Code


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

import java.util.*;

public class Main {
    public static List<String> splitByStr(String s, String delim) {
        if (isEmpty(s))
            return Collections.emptyList();
        ArrayList<String> tokens = new ArrayList<String>();
        int i = 0;
        while (i < s.length()) {
            int j = s.indexOf(delim, i);
            if (j == -1)
                break;
            tokens.add(s.substring(i, j));
            i = j + delim.length();//from  ww w.  j  av  a2s. co  m
        }
        tokens.add(s.substring(i));
        return tokens;
    }

    public static boolean isEmpty(String s) {
        return s == null || s.equals("");
    }
}

Related

  1. split2(String string, String delimiter)
  2. splitAll(String str, String delim)
  3. splitAndTrim(String string, String delim)
  4. SplitAt(String s, String delimiter)
  5. SplitAt(String str, String delimiter)
  6. splitChars(String str, String delimiters)
  7. splitFast(String text, char delim)
  8. splitForChar(final String string, final char delimiter)
  9. splitHtmlTagKeepDelimiter(String tag, String input)