Here you can find the source of split(String text, String separators, String brackets)
public static List<String> split(String text, String separators, String brackets)
//package com.java2s; /*/* ww w . j a va 2s . co m*/ * Copyright (c) 2007-2013, 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 */ import java.util.ArrayList; import java.util.List; public class Main { /** * @since 3.4 */ public static List<String> split(String text, String separators, String brackets) { List<String> result = new ArrayList<String>(); StringBuilder builder = new StringBuilder(); int length = text.length(); int bracketLevel = 0; for (int i = 0; i < length; i++) { char c = text.charAt(i); if (bracketLevel == 0 && separators.indexOf(c) != -1) { result.add(builder.toString()); builder.setLength(0); } else { builder.append(c); } if (brackets != null) { int bracket = brackets.indexOf(c); if (bracket != -1) { if ((bracket & 1) == 0) { // Opening bracket ++bracketLevel; } else { // Closing bracket --bracketLevel; } } } } result.add(builder.toString()); return result; } }