Java String Split by Delimiter split(String value, char delimiter)

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

Description

Splits a string in parts, given a specified delimiter.

License

Open Source License

Parameter

Parameter Description
value string to be split
delimiter delimiter

Declaration

public static String[] split(String value, char delimiter) 

Method Source Code

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

import java.util.ArrayList;

public class Main {
    /**//from  w  w w .ja v a2 s . c  o  m
     * Splits a string in parts, given a specified delimiter.
     *
     * @param value     string to be split
     * @param delimiter delimiter
     * @return
     */
    public static String[] split(String value, char delimiter) {
        if (value == null)
            return null;

        ArrayList<String> result = new ArrayList<>();
        int start = 0;
        for (int i = 0; i < value.length(); i++) {
            if (value.charAt(i) == delimiter) {
                result.add(value.substring(start, i));
                start = i + 1;
            }
        }
        result.add(value.substring(start));
        return result.toArray(new String[result.size()]);
    }
}

Related

  1. split(String string, String delimiter)
  2. split(String stringToSplit, char delimiter)
  3. split(String strToSplit, char delimiter)
  4. split(String text, String delimiter)
  5. split(String value, char delim)
  6. split(String value, String delimiter)
  7. split(String value, String delimiter)
  8. split(String value, String[] delimiters)
  9. split(String what, char delim)