Here you can find the source of join(Collection> strings, String delimiter)
Parameter | Description |
---|---|
strings | a parameter |
delimiter | a parameter |
public static String join(Collection<?> strings, String delimiter)
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; public class Main { /**/*from w ww. j ava2s . c o m*/ * Implements join * * @param strings * @param delimiter * @return */ public static String join(Collection<?> strings, String delimiter) { StringBuffer buffer = new StringBuffer(); Iterator<?> iter = strings.iterator(); if (iter.hasNext()) { buffer.append(iter.next().toString()); while (iter.hasNext()) { buffer.append(delimiter); buffer.append(iter.next().toString()); } } return buffer.toString(); } /** * Join on an Array of Strings * * @param strings * @param delimiter * @return */ public static String join(String[] strings, String delimiter) { if (strings != null && strings.length > 0) { Collection<Object> collection = new ArrayList<Object>(); for (String str : strings) { collection.add(str); } return join(collection, delimiter); } return null; } /** * Join on an Array of objects * * @param strings * @param delimiter * @return */ public static String join(Object[] strings, String delimiter) { if (strings != null && strings.length > 0) { Collection<Object> collection = new ArrayList<Object>(); for (Object obj : strings) { collection.add(obj.toString()); } return join(collection, delimiter); } return null; } }