Here you can find the source of getStringList(List> list, boolean useComma, boolean useBrackets, String comma)
Parameter | Description |
---|---|
list | list of objects with toString methods |
useComma | true if the list has to be comma separated |
useBrackets | true if the list has to be enclosed in brackets |
public static String getStringList(List<?> list, boolean useComma, boolean useBrackets, String comma)
//package com.java2s; /**//from w w w .java2s.c o m * Copyright (c) 1997-2013, www.tinygroup.org (luo_guo@icloud.com). * <p/> * Licensed under the GPL, Version 3.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * <p/> * http://www.gnu.org/licenses/gpl.html * <p/> * 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.List; public class Main { /** * List the toString out put of the objects in the List comma separated. If * the List is null or empty an empty string is returned. * * The same as getStringList(list, true, false) * * @see #getStringList(List, boolean, boolean) * @param list * list of objects with toString methods * @return comma separated list of the elements in the list */ public static String getStringList(List<?> list) { return getStringList(list, true, false); } /** * List the toString out put of the objects in the List that can be comma * separated. If the List is null or empty an empty string is returned. * * @param list * list of objects with toString methods * @param useComma * true if the list has to be comma separated * @param useBrackets * true if the list has to be enclosed in brackets * @return comma separated list of the elements in the list */ public static String getStringList(List<?> list, boolean useComma, boolean useBrackets, String comma) { StringBuffer buffer = new StringBuffer(); if (!useComma) { comma = ""; } if (list != null) { if (useBrackets) { buffer.append("("); } for (int i = 0; i < list.size(); i++) { buffer.append(list.get(i)).append( (i < list.size() - 1) ? comma : ""); } if (useBrackets) { buffer.append(")"); } } return buffer.toString(); } public static String getStringList(List<?> list, boolean useComma, boolean useBrackets) { return getStringList(list, useComma, useBrackets, ","); } }