Here you can find the source of fastSplit(String text, char separator)
A faster and simpler character-based string splitter based on http://forums.sun.com/thread.jspa?threadID=766801&start=0&tstart=0
Parameter | Description |
---|---|
text | parsed input string |
separator | separator character |
public static String[] fastSplit(String text, char separator)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { /**//www . j a v a 2 s . c om * A faster and simpler character-based string splitter * based on http://forums.sun.com/thread.jspa?threadID=766801&start=0&tstart=0 * * @param text parsed input string * @param separator separator character * @return splitted string array */ public static String[] fastSplit(String text, char separator) { ArrayList<String> result = new ArrayList<String>(); if (text != null && text.length() > 0) { int index1 = 0; int index2 = text.indexOf(separator); while (index2 >= 0) { String token = text.substring(index1, index2); result.add(token); index1 = index2 + 1; index2 = text.indexOf(separator, index1); } result.add(text.substring(index1)); } return result.toArray(new String[result.size()]); } }