Here you can find the source of split(final String src, final char delim)
Parameter | Description |
---|---|
src | The source string |
delim | The delimiter string to split by |
public static final String[] split(final String src, final char delim)
//package com.java2s; import java.util.ArrayList; public class Main { /**//from w w w .j a va 2s. c om * Preserves null sections. "ab..cd" would produce [ab][][cd] with '.' * @param src The source string * @param delim The delimiter string to split by * @return An array of strings. */ public static final String[] split(final String src, final char delim) { final ArrayList<String> output = new ArrayList<String>(); int index = 0; int lindex = 0; while ((index = src.indexOf(delim, lindex)) != -1) { output.add(src.substring(lindex, index)); lindex = index + 1; } output.add(src.substring(lindex)); return output.toArray(new String[output.size()]); } /** * Preserves null sections. "ab..cd" would produce [ab][][cd] with "." * @param src The source string * @param delim The delimiter string to split by * @return An array of strings. */ public static final String[] split(final String src, final String delim) { final ArrayList<String> output = new ArrayList<String>(); final int len = delim.length(); int index = 0; int lindex = 0; while ((index = src.indexOf(delim, lindex)) != -1) { output.add(src.substring(lindex, index)); lindex = index + len; } output.add(src.substring(lindex)); return output.toArray(new String[output.size()]); } }