Java String Split by Delimiter splitString(String str, char delim)

Here you can find the source of splitString(String str, char delim)

Description

split String

License

Open Source License

Declaration

static public String[] splitString(String str, char delim) 

Method Source Code

//package com.java2s;
/*/*from www .j av  a  2 s . c o  m*/
 * Copyright 2000-2013 Enonic AS
 * http://www.enonic.com/license
 */

import java.util.ArrayList;

public class Main {
    static public String[] splitString(String str, char delim) {
        return splitString(str, String.valueOf(delim));
    }

    static public String[] splitString(String str, String delim) {
        return splitString(str, delim, false);
    }

    static public String[] splitString(String str, String delim, boolean includeLastIfEmpty) {
        ArrayList<String> result = new ArrayList<String>();

        if (str != null && str.length() > 0) {
            int idx = str.indexOf(delim);

            String substr;
            while (idx != -1) {
                substr = str.substring(0, idx);
                result.add(substr);

                str = str.substring(idx + 1);
                idx = str.indexOf(delim);
            }

            if (str.length() > 0 || includeLastIfEmpty) {
                result.add(str);
            }
        }

        return result.toArray(new String[0]);
    }
}

Related

  1. splitString(final String values, final char delimiter)
  2. splitString(String data, String delimiter)
  3. splitString(String originalString, String delimeter)
  4. splitString(String source, String delimiter)
  5. splitString(String splitStr, String delim)
  6. splitString(String str, String delim)
  7. splitString(String str, String delimiter)
  8. splitString(String str, String delims)
  9. splitString(String toSplit, String delimiter)