Here you can find the source of explode(String string, String separators)
public static List<String> explode(String string, String separators)
//package com.java2s; /*/*from w w w.j a va2 s . c o m*/ * Copyright (c) 2014, 2015 Eike Stepper (Berlin, Germany) and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Eike Stepper - initial API and implementation * Yatta Solutions - [466264] Enhance UX in simple installer */ import java.util.ArrayList; import java.util.List; public class Main { public static List<String> explode(String string, String separators) { return explode(string, separators, '\\'); } public static List<String> explode(String string, String separators, char escapeCharacter) { List<String> tokens = new ArrayList<String>(); StringBuilder builder = new StringBuilder(); boolean separator = false; boolean escape = false; for (int i = 0; i < string.length(); i++) { separator = false; char c = string.charAt(i); if (!escape && c == escapeCharacter) { escape = true; } else { if (!escape && separators.indexOf(c) != -1) { tokens.add(builder.toString()); builder.setLength(0); separator = true; } else { builder.append(c); } escape = false; } } if (separator || builder.length() != 0) { tokens.add(builder.toString()); } return tokens; } }