Here you can find the source of split(String s, char delimiter)
public static String[] split(String s, char delimiter)
//package com.java2s; /*/*from www .ja va 2s. c o m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.*; public class Main { /** * Exactly like split(s, Character.toString(delimiter)) */ public static String[] split(String s, char delimiter) { return split(s, Character.toString(delimiter)); } /** * Returns the tokens of s delimited by the given delimiter, without * returning the delimiter. Repeated sequences of delimiters are treated * as one. Examples: * <pre> * split("a//b/ c /","/")=={"a","b"," c "} * split("a b", "/")=={"a b"}. * split("///", "/")=={}. * </pre> * * <b>Note that whitespace is preserved if it is not part of the delimiter.</b> * An older version of this trim()'ed each token of whitespace. */ public static String[] split(String s, String delimiters) { //Tokenize s based on delimiters, adding to buffer. StringTokenizer tokenizer = new StringTokenizer(s, delimiters); List<String> tokens = new ArrayList<String>(); while (tokenizer.hasMoreTokens()) tokens.add(tokenizer.nextToken()); return tokens.toArray(new String[0]); } }