Here you can find the source of join(final List toJoin)
Parameter | Description |
---|---|
toJoin | list of strings to join |
public static String join(final List toJoin)
//package com.java2s; /*//from www.j a v a 2 s. co m * Copyright 2001-2008 Aqris Software AS. All rights reserved. * * This program is dual-licensed under both the Common Development * and Distribution License ("CDDL") and the GNU General Public * License ("GPL"). You may elect to use one or the other of these * licenses. */ import java.util.List; public class Main { /** * Joins strings from list of strings, using comma as separator to one string. * @param toJoin list of strings to join */ public static String join(final List toJoin) { return join(toJoin, ","); } /** * Joins strings from list of strings, using custom separator. * @param toJoin list of strings to join * @param joiner string to use as separator */ public static String join(final List toJoin, final String joiner) { final String[] tmp = (String[]) toJoin.toArray(new String[toJoin.size()]); return join(tmp, joiner); } /** * Joins strings from array of strings, using comma as separator to one string. * @param toJoin array of strings to join */ public static String join(final String[] toJoin) { return join(toJoin, ","); } /** * Joins strings from array of strings, using custom separator. * @param toJoin array of strings to join * @param joiner string to use as separator */ public static String join(final String[] toJoin, final String joiner) { if (toJoin.length == 0) { return ""; } String retVal = toJoin[0]; for (int q = 1; q < toJoin.length; q++) { retVal += joiner + toJoin[q]; } return retVal; } }