Here you can find the source of split(final String toSplit)
Parameter | Description |
---|---|
toSplit | string to split |
public static String[] split(final String toSplit)
//package com.java2s; /*/*from w ww . j a va 2 s. c o m*/ * Copyright 2001-2008 Aqris Software AS. All rights reserved. * * This program is dual-licensed under both the Common Development * and Distribution License ("CDDL") and the GNU General Public * License ("GPL"). You may elect to use one or the other of these * licenses. */ import java.util.ArrayList; public class Main { public static final String[] NO_STRINGS = new String[0]; /** * Splits string into strings array separating it with comma * @param toSplit string to split * @return String array */ public static String[] split(final String toSplit) { return split(toSplit, ","); } /** * Splits strings into strings array separating it with given splitter * @param toSplit string to split * @param splitter separator in string * @return String array */ public static String[] split(final String toSplit, final String splitter) { if (toSplit == null) { return NO_STRINGS; } final ArrayList retVal = new ArrayList(); int splitPos = toSplit.indexOf(splitter); int lastPos = 0; while (splitPos > -1) { retVal.add(toSplit.substring(lastPos, splitPos)); lastPos = splitPos + splitter.length(); if (lastPos >= toSplit.length()) { break; } splitPos = toSplit.indexOf(splitter, lastPos); } if (lastPos < toSplit.length()) { retVal.add(toSplit.substring(lastPos)); } else if (lastPos == toSplit.length()) { retVal.add(""); } return (String[]) retVal.toArray(new String[retVal.size()]); } }