Here you can find the source of split(String value)
Parameter | Description |
---|---|
value | the value to split |
public static String[] split(String value)
//package com.java2s; /* ************************************************************************** * * See the NOTICE file distributed with this work for additional information * regarding copyright ownership.// ww w. j a v a 2 s . co m * * This file is licensed to you 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 { /** * Splits the given string to substrings separated by following symbols (one * or more): ',', ';', ' ', '\t', '\n', '\r'. * * @param value the value to split * @return an array of string values */ public static String[] split(String value) { List<String> list = new ArrayList<String>(); if (value != null && !"".equals(value)) { char[] array = value.toCharArray(); StringBuffer buf = new StringBuffer(); for (char ch : array) { if (ch == ',' || ch == ';' || ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') { if (buf.length() > 0) { list.add(buf.toString()); buf.delete(0, buf.length()); } } else { buf.append(ch); } } if (buf.length() > 0) list.add(buf.toString()); } return list.toArray(new String[list.size()]); } }