Here you can find the source of split(final String str, final char separator)
Parameter | Description |
---|---|
str | String to split. |
separator | Separator. |
public static List<String> split(final String str, final char separator)
//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 { /**// ww w. j a v a 2 s. c om * 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; } }