Here you can find the source of splitOnSpace(String string)
public static final String[] splitOnSpace(String string)
//package com.java2s; /******************************************************************************* * Copyright (c) 2005, 2007 Remy Suen/* www. j a v a2 s .c om*/ * 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[] splitOnSpace(String string) { int index = string.indexOf(' '); 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(' '); } if (!string.equals("")) { //$NON-NLS-1$ split.add(string); } return (String[]) split.toArray(new String[split.size()]); } }