Here you can find the source of split(String line, String seperator)
public static String[] split(String line, String seperator)
//package com.java2s; /**/* w w w.j a v a 2 s. c o m*/ * Tencent is pleased to support the open source community by making Tars available. * * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved. * * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * https://opensource.org/licenses/BSD-3-Clause * * 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. */ import java.util.ArrayList; public class Main { public static String[] split(String line, String seperator) { if (line == null || seperator == null || seperator.length() == 0) return null; ArrayList<String> list = new ArrayList<String>(); int pos1 = 0; int pos2; for (;;) { pos2 = line.indexOf(seperator, pos1); if (pos2 < 0) { list.add(line.substring(pos1)); break; } list.add(line.substring(pos1, pos2)); pos1 = pos2 + seperator.length(); } for (int i = list.size() - 1; i >= 0 && list.get(i).length() == 0; --i) { list.remove(i); } return list.toArray(new String[0]); } }