Here you can find the source of join(List
Parameter | Description |
---|---|
array | Array of strings to join together. |
delim | Delimiter to separate strings with. |
public static String join(List<String> array, String delim)
//package com.java2s; /**/* www . j ava2 s . co m*/ * $Revision$ * $Date$ * * Copyright 2006-2010 Daniel Henninger. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. */ import java.util.List; public class Main { /** * Convenience routine to perform a string join for groups in the database. * @param array Array of strings to join together. * @param delim Delimiter to separate strings with. * @return Joined string */ public static String join(List<String> array, String delim) { StringBuffer sb = join(array, delim, new StringBuffer()); return sb.toString(); } /** * Helper function for primary use join function. * @param array Array of strings to join together. * @param delim Delimiter to separate strings with. * @param sb String buffer instance to work from. * @return String buffer instance. */ static StringBuffer join(List<String> array, String delim, StringBuffer sb) { Boolean first = true; for (String s : array) { if (!first) { sb.append(delim); } else { first = false; } sb.append(s); } return sb; } }