Here you can find the source of split(String s, char delimiter)
public static String[] split(String s, char delimiter)
//package com.java2s; /**//from w w w . jav a2s . com * Copyright (c) 2000-present Liferay, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. */ import java.util.ArrayList; import java.util.List; public class Main { private static final String[] _emptyStringArray = new String[0]; public static String[] split(String s, char delimiter) { s = s.trim(); if (s.isEmpty()) { return _emptyStringArray; } List<String> values = new ArrayList<>(); int offset = 0; int pos = s.indexOf(delimiter, offset); while (pos != -1) { values.add(s.substring(offset, pos)); offset = pos + 1; pos = s.indexOf(delimiter, offset); } if (offset < s.length()) { values.add(s.substring(offset)); } return values.toArray(new String[values.size()]); } }