Here you can find the source of split(String string, char character)
public static final String[] split(String string, char character)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005, 2007 Remy Suen// ww w. j av a2 s . co m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Remy Suen <remy.suen@gmail.com> - initial API and implementation ******************************************************************************/ import java.util.ArrayList; public class Main { public static final String[] split(String string, char character) { int index = string.indexOf(character); if (index == -1) { return new String[] { string }; } ArrayList split = new ArrayList(); while (index != -1) { split.add(string.substring(0, index)); string = string.substring(index + 1); index = string.indexOf(character); } if (!string.equals("")) { //$NON-NLS-1$ split.add(string); } return (String[]) split.toArray(new String[split.size()]); } public static final String[] split(String string, String delimiter) { int index = string.indexOf(delimiter); if (index == -1) { return new String[] { string }; } int length = delimiter.length(); ArrayList split = new ArrayList(); while (index != -1) { split.add(string.substring(0, index)); string = string.substring(index + length); index = string.indexOf(delimiter); } if (!string.equals("")) { //$NON-NLS-1$ split.add(string); } return (String[]) split.toArray(new String[split.size()]); } public static final String[] split(String string, String delimiter, int limit) { int index = string.indexOf(delimiter); if (index == -1) { return new String[] { string }; } int count = 0; int length = delimiter.length(); ArrayList split = new ArrayList(limit); while (index != -1 && count < limit - 1) { split.add(string.substring(0, index)); string = string.substring(index + length); index = string.indexOf(delimiter); count++; } if (!string.equals("")) { //$NON-NLS-1$ split.add(string); } return (String[]) split.toArray(new String[split.size()]); } }