Java String Split by Delimiter split(String input, String delimiter)

Here you can find the source of split(String input, String delimiter)

Description

Method split.

License

Open Source License

Parameter

Parameter Description
input a parameter
delimiter a parameter

Return

List

Declaration

public static List<String> split(String input, String delimiter) 

Method Source Code

//package com.java2s;

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/* w w w.  j  ava2s . c  om*/
     * Method split. Splits a string into multiple strings as delimited by the 'delimiter' string
     * 
     * @param input
     * @param delimiter
     * @return List
     */
    public static List<String> split(String input, String delimiter) {
        if (input == null)
            return null;

        List<String> splitList = new ArrayList<String>(16);
        if (input.length() == 0)
            return splitList;

        int startIndex = 0;
        int endIndex;

        do {
            endIndex = input.indexOf(delimiter, startIndex);
            if (endIndex > -1) {
                // Extract the element and adjust new starting point
                splitList.add(input.substring(startIndex, endIndex));
                startIndex = endIndex + delimiter.length();
            } else {
                // Last element
                splitList.add(input.substring(startIndex));
            }

        } while (endIndex > -1);

        // Return the list
        return splitList;
    }
}

Related

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