Here you can find the source of splitString(String string, char ch)
public static List<String> splitString(String string, char ch)
//package com.java2s; /******************************************************************************* * Copyright (c) 2012 EclipseSource 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:/*ww w . ja v a 2 s.c om*/ * EclipseSource - initial API and implementation ******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { public static List<String> splitString(String string, char ch) { return splitString(string, ch, false); } public static List<String> splitString(String string, char ch, boolean skipElementLastIfEmpty) { List<String> parts = new ArrayList<String>(); int beginIndex = 0; int endIndex = string.indexOf(ch); while (endIndex != -1) { String nextPart = string.substring(beginIndex, endIndex); parts.add(nextPart); beginIndex = endIndex + 1; endIndex = string.indexOf(ch, beginIndex); } if (!skipElementLastIfEmpty || beginIndex < string.length()) { String lastPart = string.substring(beginIndex, string.length()); parts.add(lastPart); } return parts; } }