Here you can find the source of join(Iterable
Parameter | Description |
---|---|
sequence | The items to be converted into string. |
delimiter | The delimiter to be used between distinct items of the collection. |
public static <T> String join(Iterable<T> sequence, String delimiter)
//package com.java2s; /*/*from w w w . ja va 2s .c o m*/ * Entwined STM * * (c) Copyright 2013 CERN. This software is distributed under the terms of the Apache License Version 2.0, copied * verbatim in the file "COPYING". In applying this licence, CERN does not waive the privileges and immunities granted * to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. */ import java.util.Iterator; public class Main { /** * Join string representation of the elements of the given collection separated with the given delimiter. * * @param sequence The items to be converted into string. * @param delimiter The delimiter to be used between distinct items of the collection. * @return String representations of the collection's items separated with the given delimiter. */ public static <T> String join(Iterable<T> sequence, String delimiter) { if (null == sequence) { return "null"; } if (null == delimiter) { delimiter = ""; } Iterator<T> iterator = sequence.iterator(); if (!iterator.hasNext()) { return ""; } StringBuffer buffer = new StringBuffer(256); buffer.append(iterator.next()); while (iterator.hasNext()) { buffer.append(delimiter); buffer.append(iterator.next()); } return buffer.toString(); } }