Java String Split by Delimiter splitString(String data, String delimiter)

Here you can find the source of splitString(String data, String delimiter)

Description

Split the input string "data" using the delimiter and return as list of strings for the slices obtained

License

Open Source License

Parameter

Parameter Description
data a parameter
delimiter a parameter

Declaration

public static ArrayList<String> splitString(String data, String delimiter) 

Method Source Code

//package com.java2s;
/**/*from w w  w.ja  v a 2 s .co m*/
 * Copyright 2016 LinkedIn Corp. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */

import java.util.ArrayList;
import java.util.Arrays;

public class Main {
    /**
     * Split the input string "data" using the delimiter and return as list of strings for the slices obtained
     * @param data
     * @param delimiter
     * @return
     */
    public static ArrayList<String> splitString(String data, String delimiter) {
        if (data == null) {
            throw new IllegalArgumentException("Passed in string is null ");
        }
        ArrayList<String> toReturn = new ArrayList<String>();
        String[] slices = data.split(delimiter);
        toReturn.addAll(Arrays.asList(slices));
        return toReturn;
    }
}

Related

  1. splitSimpleLimit(String str, String delimiter, int limitSize)
  2. splitSqlScript(String script, char delim, List statements)
  3. splitStr(String str, char delimiter, boolean trim)
  4. splitString(CharSequence s, char delim)
  5. splitString(final String values, final char delimiter)
  6. splitString(String originalString, String delimeter)
  7. splitString(String source, String delimiter)
  8. splitString(String splitStr, String delim)
  9. splitString(String str, char delim)