Here you can find the source of splitToCollection(String list, String separator, Collection
Parameter | Description |
---|---|
list | a parameter |
separator | a parameter |
dest | a parameter |
public static Collection<String> splitToCollection(String list, String separator, Collection<String> dest)
//package com.java2s; /**//from w w w. java2 s. com * Copyright 2016 Polydeuce-Sys Ltd * * 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.Collection; public class Main { private static final String DEFAULT_SEPARATOR = ","; /** * Split the given String on a separator and add the (trimmed) results to a given {@link Collection} * @param list * @param separator * @param dest * @return */ public static Collection<String> splitToCollection(String list, String separator, Collection<String> dest) { String[] parts = list.split(separator); for (String s : parts) { if (!s.equals("")) { dest.add(s.trim()); } } return dest; } /** * Split a comma separated String and put the results in the given {@link Collection} * @param list * @param dest * @return */ public static Collection<String> splitToCollection(String list, Collection<String> dest) { return splitToCollection(list, DEFAULT_SEPARATOR, dest); } }