Here you can find the source of getTokens(String msg, String delim)
public static String[] getTokens(String msg, String delim)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2010 IBM Corporation and others. * 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:/*from w w w . jav a2s . c o m*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.util.*; public class Main { public static String[] getTokens(String msg, String delim) { return getTokens(msg, delim, false); } public static String[] getTokens(String msg, String delim, boolean returnDelims) { StringTokenizer targetST = new StringTokenizer(msg, delim, returnDelims); String[] tokens = new String[targetST.countTokens()]; ArrayList list = new ArrayList(targetST.countTokens()); while (targetST.hasMoreTokens()) { list.add(targetST.nextToken()); } list.toArray(tokens); return tokens; } }