Here you can find the source of join(String glue, Collection pieces)
Parameter | Description |
---|---|
glue | Token to place between Strings. |
pieces | Collection of Strings to join. |
public final static String join(String glue, Collection pieces)
//package com.java2s; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; public class Main { /**// w ww . ja v a 2s. c om * Join an Iteration of Strings together. * * <h5>Example</h5> * * <pre> * // get Iterator of Strings ("abc","def","123"); * Iterator i = getIterator(); * out.print( TextUtils.join(", ",i) ); * // prints: "abc, def, 123" * </pre> * * @param glue Token to place between Strings. * @param pieces Iteration of Strings to join. * @return String presentation of joined Strings. */ public final static String join(String glue, Iterator pieces) { StringBuffer s = new StringBuffer(); while (pieces.hasNext()) { s.append(pieces.next().toString()); if (pieces.hasNext()) { s.append(glue); } } return s.toString(); } /** * Join an array of Strings together. * * @param glue Token to place between Strings. * @param pieces Array of Strings to join. * @return String presentation of joined Strings. * * @see #join(String, java.util.Iterator) */ public final static String join(String glue, String[] pieces) { return join(glue, Arrays.asList(pieces).iterator()); } /** * Join a Collection of Strings together. * * @param glue Token to place between Strings. * @param pieces Collection of Strings to join. * @return String presentation of joined Strings. * * @see #join(String, java.util.Iterator) */ public final static String join(String glue, Collection pieces) { return join(glue, pieces.iterator()); } }