Here you can find the source of split(String str, char delim)
Parameter | Description |
---|---|
str | The string to split. |
delim | The delimiter to split on. |
public static String[] split(String str, char delim)
//package com.java2s; /*//from w w w .ja v a 2 s . c om * Copyright (C) 2012 Ed Schaller <schallee@darkmist.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.ArrayList; import java.util.List; public class Main { private static final String[] EMPTY_STRING_ARRAY = new String[0]; /** * Split a string on a delimiter. * @param str The string to split. * @param delim The delimiter to split on. * @return The substrings of str that were seperated by delim. */ public static String[] split(String str, char delim) { List<String> strs; int len; int start, end; if (str == null) return EMPTY_STRING_ARRAY; if ((len = str.length()) == 0) return new String[] { "" }; strs = new ArrayList<String>(len); for (start = 0; start < len && (end = str.indexOf(delim, start)) >= 0; start = end + 1) strs.add(str.substring(start, end)); strs.add(str.substring(start)); return strs.toArray(EMPTY_STRING_ARRAY); } }