Here you can find the source of convertStringToList(String string, String delimiter, boolean trim)
Parameter | Description |
---|---|
string | String to convert to list |
delimiter | Delimiter of list elements |
trim | Whether or not to trim tokens befor putting them in list |
public static List convertStringToList(String string, String delimiter, boolean trim)
//package com.java2s; /*//www. j a va 2s . c om * Copyright 2004 Blandware (http://www.blandware.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.*; public class Main { /** * Converts string to list. The string is assumed to be a sequence of some * elements separated with delimiter. * * @param string String to convert to list * @param delimiter Delimiter of list elements * @param trim Whether or not to trim tokens befor putting them in list * @return List */ public static List convertStringToList(String string, String delimiter, boolean trim) { if (string == null || string.length() == 0) { return new LinkedList(); } String[] members = string.split(delimiter); List list = Collections.synchronizedList(new LinkedList()); for (int i = 0; i < members.length; i++) { String member = members[i]; if (trim) { member = member.trim(); } list.add(member); } return list; } }