Here you can find the source of splitString(String bigString, String splitter)
Parameter | Description |
---|---|
bigString | The string to be split |
splitter | The splitter |
public static List<String> splitString(String bigString, String splitter)
//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; } }