Java String Split by Delimiter split(String s, char delim)

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

Description

split

License

Open Source License

Declaration

public static ArrayList<String> split(String s, char delim) 

Method Source Code

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

import java.util.ArrayList;

public class Main {
    public static ArrayList<String> split(String s, char delim) {
        ArrayList<String> rv = new ArrayList<String>();
        int length = s.length();
        int cur = -1;
        int next;

        if (length == 0) {
            return rv;
        }/*from   w w  w. j  a v  a2s  .co  m*/

        while (true) {
            next = s.indexOf(delim, cur + 1);
            if (next == -1) {
                rv.add(s.substring(cur + 1));
                break;
            } else if (next == length - 1) {
                rv.add(s.substring(cur + 1, next));
                break;
            } else {
                rv.add(s.substring(cur + 1, next));
                cur = next;
            }
        }
        return rv;
    }
}

Related

  1. split(String input, String delimiter)
  2. split(String input, String delimiter)
  3. split(String input, String... delimiters)
  4. split(String input, String... delimiters)
  5. split(String inputStr, String delimeter, String enclosureStr)
  6. split(String s, char delim)
  7. split(String s, char delimiter)
  8. split(String s, char delimiter)
  9. split(String s, char delimiter)