Here you can find the source of split(String s, char divider)
Parameter | Description |
---|---|
s | the string to split |
divider | the character on which to split. Occurrences of this character are not included in the output |
public static ArrayList split(String s, char divider)
//package com.java2s; /**//from ww w . j ava2s . c om * Util.java * @author John Green * 27-Oct-2002 * www.joanju.com * * Copyright (c) 2002 Joanju Limited. * 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 * */ import java.util.*; public class Main { /** * Split a string into pieces based on the given divider character. * Used for Java 1.3 compatability - String.split() is new as of 1.4. * @deprecated Use Java 1.4 String.split() instead. * @param s the string to split * @param divider the character on which to split. Occurrences of * this character are not included in the output * @return An ArrayList of the pieces. */ public static ArrayList split(String s, char divider) { ArrayList retList = new ArrayList(); int last = 0; int sLength = s.length(); int i = 0; for (; i < sLength; ++i) { if (s.charAt(i) == divider) { retList.add(s.substring(last, i)); last = i + 1; } } retList.add(s.substring(last, i)); return retList; } }