Here you can find the source of splitStaySeparator(String str, char token)
Parameter | Description |
---|---|
str | a standard str |
token | a token ( not pattern !!! ) |
public static String[] splitStaySeparator(String str, char token)
//package com.java2s; //License from project: LGPL import java.util.ArrayList; public class Main { /**/*from w w w . j a v a 2s. c om*/ * split a String, if there are no character between two token this method place * a empty String ( != String.split ) * * @param str * a standard str * @param token * a token ( not pattern !!! ) * @return a array of String with the separator */ public static String[] splitStaySeparator(String str, char token) { int i = str.indexOf(token); int start = 0; ArrayList<String> arrayList = new ArrayList<String>(); while (i >= 0) { arrayList.add(str.substring(start, i)); start = i + 1; arrayList.add(str.substring(i, i + 1)); i = str.indexOf(token, start); } arrayList.add(str.substring(start, str.length())); String[] res = new String[arrayList.size()]; arrayList.toArray(res); return res; } /** * split a String, if there are no character between two token this method place * a empty String ( != String.split ) * * @param str * a standard str * @param token * a token ( not pattern !!! ) * @return a array of String with the separator */ public static String[] splitStaySeparator(String str, String token) { if ((token == null) || (token.length() == 0)) { return new String[] { str }; } ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add(str); char[] sep = token.toCharArray(); for (char c : sep) { ArrayList<String> newArrayList = new ArrayList<String>(); for (String string : arrayList) { String[] splitedString = splitStaySeparator(string, c); for (String string2 : splitedString) { newArrayList.add(string2); } } arrayList = newArrayList; } String[] res = new String[arrayList.size()]; arrayList.toArray(res); return res; } }