Here you can find the source of split(String s, char separator)
public static List<String> split(String s, char separator)
//package com.java2s; /******************************************************************************* * Copyright (c) 2015 Oliver Br?samle/*from w ww . j a v a2s .c om*/ * 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: * Oliver Br?samle - initial API and implementation and/or initial documentation * Andrey Loskutov <loskutov@gmx.de> - review, cleanup and bugfixes *******************************************************************************/ import java.util.ArrayList; import java.util.List; public class Main { public static List<String> split(String s, char separator) { int i = s.indexOf(separator); List<String> list = new ArrayList<>(); if (i < 0) { list.add(s); return list; } for (; i >= 0 && i < s.length();) { String sub = s.substring(0, i).trim(); if (!sub.isEmpty()) { list.add(sub); } s = s.substring(i + 1).trim(); i = s.indexOf(separator); if (i < 0) { if (!s.isEmpty()) { list.add(s); } break; } } return list; } }