Here you can find the source of split(String input, String delimiter)
Parameter | Description |
---|---|
input | a parameter |
delimiter | a parameter |
public static List<String> split(String input, String delimiter)
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { /**/* w w w. j ava2s . c om*/ * Method split. Splits a string into multiple strings as delimited by the 'delimiter' string * * @param input * @param delimiter * @return List */ public static List<String> split(String input, String delimiter) { if (input == null) return null; List<String> splitList = new ArrayList<String>(16); if (input.length() == 0) return splitList; int startIndex = 0; int endIndex; do { endIndex = input.indexOf(delimiter, startIndex); if (endIndex > -1) { // Extract the element and adjust new starting point splitList.add(input.substring(startIndex, endIndex)); startIndex = endIndex + delimiter.length(); } else { // Last element splitList.add(input.substring(startIndex)); } } while (endIndex > -1); // Return the list return splitList; } }