Here you can find the source of split(final String str, final char[] separators)
Parameter | Description |
---|---|
str | String to split. |
separators | Separators. |
public static List<String> split(final String str, final char[] separators)
//package com.java2s; // and/or modify it under the terms of the GNU General Public License import java.util.ArrayList; import java.util.List; public class Main { /**//from w ww. jav a2 s. co m * Split string to array. * * @param str * String to split. * @param separators * Separators. * @return Split values. */ public static List<String> split(final String str, final char[] separators) { int lastPos = 0; List<String> arr = new ArrayList<String>(); for (int pos = 0; pos != str.length(); ++pos) { char ch = str.charAt(pos); for (char sep : separators) { if (ch == sep) { if (lastPos != pos) { arr.add(str.substring(lastPos, pos)); } lastPos = pos + 1; break; } } } if (lastPos != str.length()) { arr.add(str.substring(lastPos, str.length())); } return arr; } /** * Split string to array. * * @param str * String to split. * @param separator * Separator. * @return Split values. */ public static List<String> split(final String str, final char separator) { List<String> arr = new ArrayList<String>(); int pos = 0, lastPos = 0; while ((pos = str.indexOf(separator, lastPos)) != -1) { arr.add(str.substring(lastPos, pos)); lastPos = pos + 1; } if (str.length() > lastPos) { arr.add(str.substring(lastPos)); } else { arr.add(""); } return arr; } /** * Split string to array. * * @param str * String to split. * @param separator * Separator. * @return Split values. */ public static List<String> split(final String str, final String separator) { List<String> arr = new ArrayList<String>(); int pos = 0, lastPos = 0; while ((pos = str.indexOf(separator, lastPos)) != -1) { arr.add(str.substring(lastPos, pos)); lastPos = pos + separator.length(); } if (str.length() > lastPos) { arr.add(str.substring(lastPos)); } else { arr.add(""); } return arr; } }