Here you can find the source of split(String str, char delimiter, boolean trim)
public static String[] split(String str, char delimiter, boolean trim)
//package com.java2s; /*//from www .j ava 2 s . c o m * Copyright (c) 2006-2012 Nuxeo SA (http://nuxeo.com/) 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: * Nuxeo - initial API and implementation * * $Id: StringUtils.java 28482 2008-01-04 15:33:39Z sfermigier $ */ import java.util.ArrayList; import java.util.List; public class Main { public static String[] split(String str, char delimiter, boolean trim) { int s = 0; int e = str.indexOf(delimiter, s); if (e == -1) { if (trim) { str = str.trim(); } return new String[] { str }; } List<String> ar = new ArrayList<String>(); do { String segment = str.substring(s, e); if (trim) { segment = segment.trim(); } ar.add(segment); s = e + 1; e = str.indexOf(delimiter, s); } while (e != -1); int len = str.length(); if (s < len) { String segment = str.substring(s); if (trim) { segment = segment.trim(); } ar.add(segment); } else { ar.add(""); } return ar.toArray(new String[ar.size()]); } }