Here you can find the source of split(String s, String separator)
Parameter | Description |
---|---|
s | the string to split. |
separator | the separator to use. |
public static String[] split(String s, String separator)
//package com.java2s; //License from project: LGPL import java.util.ArrayList; public class Main { /**// ww w. j a v a2s. com * Mimics the the Java SE {@link String#split(String)} method. * * @param s the string to split. * @param separator the separator to use. * @return the array of split strings. */ public static String[] split(String s, String separator) { int separatorlen = separator.length(); ArrayList tokenList = new ArrayList(); String tmpString = "" + s; int pos = tmpString.indexOf(separator); while (pos >= 0) { String token = tmpString.substring(0, pos); tokenList.add(token); tmpString = tmpString.substring(pos + separatorlen); pos = tmpString.indexOf(separator); } if (tmpString.length() > 0) tokenList.add(tmpString); String[] res = new String[tokenList.size()]; for (int i = 0; i < res.length; i++) { res[i] = (String) tokenList.get(i); } return res; } }