Here you can find the source of concat(List> list, String delim)
Parameter | Description |
---|---|
list | List to Serialize |
delim | Delimiting Character |
public static String concat(List<?> list, String delim)
//package com.java2s; /**//from w w w . j a va 2 s. c o m * Pennyworth - A new smarthome protocol. * Copyright (C) 2012 Dream-Crusher Labs LLC * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.util.List; public class Main { /** * Used to turn a list into a string with the specified delimiter. * If there are less than 2 items in the list the delimiter will * not appear. * * @param list List to Serialize * @param delim Delimiting Character * @return Serialized String */ public static String concat(List<?> list, String delim) { String ret = list.get(0) + ""; for (int i = 1; i < list.size(); i++) { ret = ret + delim + list.get(i); } return ret; } /** * Used to turn a list into a string with the specified delimiter. * If there are less than 2 items in the list the delimiter will * not appear. * * @param list List to Serialize * @param delim Delimiting Character * @return Serialized String */ public static String concat(Object[] list, String delim) { String ret = list[0] + ""; for (int i = 1; i < list.length; i++) { ret = ret + delim + list[i]; } return ret; } }