Here you can find the source of join(T[] array, String separator)
Parameter | Description |
---|---|
T | a parameter |
array | a parameter |
separator | a parameter |
public static <T> String join(T[] array, String separator)
//package com.java2s; // License & terms of use: http://www.unicode.org/copyright.html#License import java.util.Iterator; public class Main { /**/*from w w w .java 2 s . co m*/ * Join an array of items. * @param <T> * @param array * @param separator * @return string */ public static <T> String join(T[] array, String separator) { StringBuffer result = new StringBuffer(); for (int i = 0; i < array.length; ++i) { if (i != 0) result.append(separator); result.append(array[i]); } return result.toString(); } /** * Join a collection of items. * @param <T> * @param collection * @param <U> * @param array * @param separator * @return string */ public static <T, U extends Iterable<T>> String join(U collection, String separator) { StringBuffer result = new StringBuffer(); boolean first = true; for (Iterator it = collection.iterator(); it.hasNext();) { if (first) first = false; else result.append(separator); result.append(it.next()); } return result.toString(); } }