Here you can find the source of splitInclusive(CharSequence input, char[] splitChars)
public static String[] splitInclusive(CharSequence input, char[] splitChars)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; public class Main { public static String[] splitInclusive(CharSequence input, char[] splitChars) { ArrayList<String> splited = new ArrayList<>(); String readthusfar = ""; for (int i = 0; i < input.length(); i++) { char readChar = input.charAt(i); if (containsChar(splitChars, readChar)) { if (!readthusfar.isEmpty()) { splited.add(readthusfar); readthusfar = ""; }//from w w w. j a v a 2 s. c o m splited.add(String.valueOf(readChar)); continue; } readthusfar += readChar; } if (!readthusfar.isEmpty()) { splited.add(readthusfar); } String[] resultAsArray = new String[splited.size()]; resultAsArray = splited.toArray(resultAsArray); return resultAsArray; } public static boolean containsChar(char[] array, char v) { for (char e : array) if (e == v) return true; return false; } }