Here you can find the source of split(String str, char splitChar)
Parameter | Description |
---|---|
str | a parameter |
splitChar | a parameter |
public static String[] split(String str, char splitChar)
//package com.java2s; import java.util.ArrayList; public class Main { /**//from w w w . ja v a 2s. co m * Parse a string into a series of string tokens using the specified * delimiter. * * @param str * @param splitChar * @return Array of string token */ public static String[] split(String str, char splitChar) { if (str == null) { return null; } if (str.trim().equals("")) { return new String[0]; } if (str.indexOf(splitChar) == -1) { String[] strArray = new String[1]; strArray[0] = str; return strArray; } ArrayList<String> list = new ArrayList<String>(); int prevPos = 0; for (int pos = str.indexOf(splitChar); pos >= 0; pos = str.indexOf(splitChar, (prevPos = (pos + 1)))) { list.add(str.substring(prevPos, pos)); } list.add(str.substring(prevPos, str.length())); return (String[]) list.toArray(new String[list.size()]); } }