Here you can find the source of split(String input, char delimiter)
Parameter | Description |
---|---|
input | string to split. |
delimiter | delimiter |
public static String[] split(String input, char delimiter)
//package com.java2s; /*// w w w .j ava 2 s . c om Copyright 2009-2014 Igor Polevoy 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.*; public class Main { /** * Splits a string into an array using a provided delimiter. The split chunks are also trimmed. * * @param input string to split. * @param delimiter delimiter * @return a string into an array using a provided delimiter */ public static String[] split(String input, char delimiter) { if (input == null) throw new NullPointerException("input cannot be null"); List<String> tokens = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(input, new String(new byte[] { (byte) delimiter })); while (st.hasMoreTokens()) { tokens.add(st.nextToken().trim()); } return tokens.toArray(new String[tokens.size()]); } }