Here you can find the source of toFriendlyString(Iterable> iterable, String seperator)
Parameter | Description |
---|---|
iterable | The Iterable of elements |
seperator | The seperator between every element |
public static String toFriendlyString(Iterable<?> iterable, String seperator)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; public class Main { /**/*w w w . j a va 2 s .c o m*/ * Turns every element of the iterable into a friendly string which can be used in a statement * * @param iterable The Iterable of elements * @param seperator The seperator between every element */ public static String toFriendlyString(Iterable<?> iterable, String seperator) { Iterator<?> iter = iterable.iterator(); StringBuilder builder = new StringBuilder(); while (iter.hasNext()) { Object next = iter.next(); builder.append(next); if (iter.hasNext()) builder.append(seperator); } return builder.toString(); } /** * Turns every element of the Array into a friendly string which can be used in a statement * * @param o The Array of elements * @param seperator The seperator between every element */ public static String toFriendlyString(Object[] o, String seperator) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < o.length; i++) { Object next = o[i]; builder.append(next); if (o.length >= i + 2) builder.append(seperator); } return builder.toString(); } }