Here you can find the source of split(String value, char splitChar)
Parameter | Description |
---|---|
value | a parameter |
splitChar | a parameter |
public static String[] split(String value, char splitChar)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004,2009 Actuate Corporation. * 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:/* ww w .j av a 2 s . co m*/ * Actuate Corporation - initial API and implementation *******************************************************************************/ import java.util.ArrayList; public class Main { /** * split strings by the character. * * It implements javascript's behavior as always return count(splitChar)+1 * * for example, split char is '/': * * <dl> * <li>'/' => ['', '']</li> * <li>'/abc/' => ['', 'abc', '']</li> * <li>'abc' => 'abc'</li> * </dl> * * @param value * @param splitChar * @return */ public static String[] split(String value, char splitChar) { ArrayList<String> result = new ArrayList<String>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char ch = value.charAt(i); if (ch == splitChar) { result.add(sb.toString()); sb.setLength(0); } else { sb.append(ch); } } result.add(sb.toString()); return result.toArray(new String[result.size()]); } }