Here you can find the source of split(String strToSplit, char delimiter)
Parameter | Description |
---|---|
strToSplit | a parameter |
delimiter | a parameter |
public static List<String> split(String strToSplit, char delimiter)
//package com.java2s; /**//w w w . j av a 2 s . c o m * The contents of this file may be used under the terms of the Apache License, Version 2.0 * in which case, the provisions of the Apache License Version 2.0 are applicable instead of those above. * * Copyright 2014, Ecarf.io * * 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. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Split a string using indexOf and subsString, this is proved to be * faster than String.split and StringUtils.split * @param strToSplit * @param delimiter * @return */ public static List<String> split(String strToSplit, char delimiter) { List<String> parts = new ArrayList<>(); int foundPosition; int startIndex = 0; String part; while ((foundPosition = strToSplit.indexOf(delimiter, startIndex)) > -1) { part = strToSplit.substring(startIndex, foundPosition); if (part.length() > 0) { parts.add(part); } startIndex = foundPosition + 1; } if (startIndex < strToSplit.length()) { parts.add(strToSplit.substring(startIndex)); } return parts; } }