Here you can find the source of listToString(final List> list, final String separator)
list
separated by separator
.
Parameter | Description |
---|---|
list | the list to print |
separator | to use between elements |
public static String listToString(final List<?> list, final String separator)
//package com.java2s; /*/*from w w w . j a va 2 s .c o m*/ * Copyright 2015-2018 Ping Identity Corporation * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License (GPLv2 only) * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see <http://www.gnu.org/licenses>. */ import java.util.List; public class Main { /** * Creates a string representation of the elements in the * <code>list</code> separated by <code>separator</code>. * * @param list the list to print * @param separator to use between elements * * @return String representing the list */ public static String listToString(final List<?> list, final String separator) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { sb.append(list.get(i)); if (i < list.size() - 1) { sb.append(separator); } } return sb.toString(); } }