Here you can find the source of loadListFromStrings(final String commaDelimitedStrings, final boolean sortList)
List
containing those values.
Parameter | Description |
---|---|
commaDelimitedStrings | A string containing a comma-delimited list of values. |
sortList | If this is <code>true</code> then the returned list will be sorted. |
List
containing the separated values.
public static ArrayList<String> loadListFromStrings(final String commaDelimitedStrings, final boolean sortList)
//package com.java2s; /*/*from www . j a va 2s . c o m*/ * Copyright 2006-2014 Andy King (GreatLogic.com) * * 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.Collections; public class Main { /** * Converts a string containing a comma-delimited list of values into a <code>List</code> containing * those values. * @param commaDelimitedStrings A string containing a comma-delimited list of values. * @param sortList If this is <code>true</code> then the returned list will be sorted. * @return A <code>List</code> containing the separated values. */ public static ArrayList<String> loadListFromStrings(final String commaDelimitedStrings, final boolean sortList) { return loadListFromStrings(null, commaDelimitedStrings, sortList); } /** * Converts a string containing a comma-delimited list of values into a <code>List</code> containing * those values. * @param stringList The <code>List</code> into which the values will be placed. If this is * <code>null</code> then a new <code>List</code> will be created. * @param commaDelimitedStrings A string containing a comma-delimited list of values. * @param sortList If this is <code>true</code> then the returned list will be sorted. * @return A <code>List</code> containing the separated values. */ public static ArrayList<String> loadListFromStrings(final ArrayList<String> stringList, final String commaDelimitedStrings, final boolean sortList) { final ArrayList<String> result = stringList == null ? new ArrayList<String>(20) : stringList; try { final String[] strings = commaDelimitedStrings.split(","); result.clear(); Collections.addAll(result, strings); if (sortList) { Collections.sort(result); } } catch (final Exception e) { // the list will have everything up to the first exception } return result; } }