Here you can find the source of splitWithEscape(String s, String splitChars)
public static List<String> splitWithEscape(String s, String splitChars)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { public static final char escapeChar = '\\'; public static List<String> splitWithEscape(String s, String splitChars) { if (splitChars == null) { splitChars = ""; }/*from w w w . j av a2 s .co m*/ List<String> result = new ArrayList<String>(); if (s == null) { return result; } boolean escaped = false; StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { char ch = (char) s.codePointAt(i); if (escaped) { sb.append(ch); escaped = false; } else { if (ch == escapeChar) { escaped = true; continue; } else { if (splitChars.indexOf(ch) > -1) { result.add(sb.toString()); sb = new StringBuilder(); } else { sb.append(ch); } } } } result.add(sb.toString()); return result; } }