Java String Split splitString(String bigString, String splitter)

Here you can find the source of splitString(String bigString, String splitter)

Description

Split a string into a list of substrings separated by splitter.

License

LGPL

Parameter

Parameter Description
bigString The string to be split
splitter The splitter

Return

a list of strings

Declaration

public static List<String> splitString(String bigString, String splitter) 

Method Source Code

//package com.java2s;
/*/*from w w w . ja  va2  s  .c om*/
 *   This software is distributed under the terms of the FSF 
 *   Gnu Lesser General Public License (see lgpl.txt). 
 *
 *   This program is distributed WITHOUT ANY WARRANTY. See the
 *   GNU General Public License for more details.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Split a string into a list of substrings separated by splitter.
     * 
     * @param bigString  The string to be split
     * @param splitter    The splitter
     * @return a list of strings
     */
    public static List<String> splitString(String bigString, String splitter) {
        if (bigString == null || "".equals(bigString.trim()))
            return new ArrayList<String>();

        List<String> dataList = new ArrayList<String>();
        int spliterLen = splitter.length();
        int index = bigString.indexOf(splitter);

        while (index != -1) {
            String frontString = bigString.substring(0, index);
            dataList.add(frontString);

            bigString = bigString.substring(index + spliterLen);
            index = bigString.indexOf(splitter);
        }

        if (!bigString.equals(""))
            dataList.add(bigString);

        //add the original string to the return list if nothing is split. 
        if (dataList.size() == 0)
            dataList.add(bigString);

        return dataList;
    }
}

Related

  1. splitSimpleQueries(String queryString)
  2. splitSQL(List list, String sql)
  3. splitSQLColumns(String sql)
  4. splitStep(String step)
  5. splitStr(String str, int toCount)
  6. splitString(String hexString, int partSize)
  7. splitString(String s)
  8. splitString(String s)
  9. splitString(String s)