Here you can find the source of split(String str, char c)
public static String[] split(String str, char c)
//package com.java2s; /**//from ww w . ja va 2 s . com * * Copyright 2008 - 2009 * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * @project loonframework * @author chenpeng * @email?ceponline@yahoo.com.cn * @version 0.1 */ import java.util.ArrayList; import java.util.List; public class Main { public static String[] split(String str, char c) { str += c; int n = 0; for (int i = 0; i < str.length(); i++) { if (str.charAt(i) == c) { n++; } } String out[] = new String[n]; for (int i = 0; i < n; i++) { int index = str.indexOf(c); out[i] = str.substring(0, index); str = str.substring(index + 1, str.length()); } return out; } public static int length(String s) { if (s == null) return 0; else return s.getBytes().length; } public static List subString(String in, String open, String end) { List list = new ArrayList(); while (true) { int from = in.indexOf(open, 0); if (from == -1) break; in = in.substring(from + open.length(), in.length()); int to = in.indexOf(open, 0); int mid = in.indexOf(open); if ((mid > to || mid == -1) && to != -1) { list.add(in.substring(0, to)); } } return list; } }