Here you can find the source of split(String s)
SPLIT_START {string} { SPLIT_DELIM {string}} SPLIT_END(e.g.,"[one, two, three]"
).License
Open Source LicenseDeclaration
public static String[] split(String s)Method Source Code
//package com.java2s; /* ******************************************************************* * Copyright (c) 1999-2000 Xerox Corporation. * All rights reserved. //from w w w .ja va 2 s .c o m * 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: * Xerox/PARC initial implementation * ******************************************************************/ import java.util.ArrayList; public class Main { /** Delimiter used by split(String) (and ArrayList.toString()?) */ public static final String SPLIT_DELIM = ", "; /** prefix used by split(String) (and ArrayList.toString()?) */ public static final String SPLIT_START = "["; /** suffix used by split(String) (and ArrayList.toString()?) */ public static final String SPLIT_END = "]"; /** * Split input into substrings on the assumption that it is * either only one string or it was generated using List.toString(), * with tokens * <pre>SPLIT_START {string} { SPLIT_DELIM {string}} SPLIT_END<pre> * (e.g., <code>"[one, two, three]"</code>). */ public static String[] split(String s) { if (null == s) { return null; } if ((!s.startsWith(SPLIT_START)) || (!s.endsWith(SPLIT_END))) { return new String[] { s }; } s = s.substring(SPLIT_START.length(), s.length() - SPLIT_END.length()); final int LEN = s.length(); int start = 0; final ArrayList result = new ArrayList(); final String DELIM = ", "; int loc = s.indexOf(SPLIT_DELIM, start); while ((start < LEN) && (-1 != loc)) { result.add(s.substring(start, loc)); start = DELIM.length() + loc; loc = s.indexOf(SPLIT_DELIM, start); } result.add(s.substring(start)); return (String[]) result.toArray(new String[0]); } }Related