Here you can find the source of split(String input)
Parameter | Description |
---|---|
input | the string to split, possibly null or empty |
public static String[] split(String input)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.util.ArrayList; import java.util.List; public class Main { /**/*from w w w. j a v a2 s .co m*/ * Splits an input string into a an array of strings, seperating * at commas. * * @param input the string to split, possibly null or empty * @return an array of the strings split at commas */ public static String[] split(String input) { return split(',', input); } public static String[] split(final char delimiter, final String input) { if (input == null) return new String[0]; List<String> strings = new ArrayList<String>(); int startx = 0; int cursor = 0; int length = input.length(); while (cursor < length) { if (input.charAt(cursor) == delimiter) { String item = input.substring(startx, cursor); strings.add(item); startx = cursor + 1; } cursor++; } if (startx < length) strings.add(input.substring(startx)); return strings.toArray(new String[strings.size()]); } }