Here you can find the source of asStringOn(StringBuilder sb, Object[] items, String separator)
Parameter | Description |
---|---|
sb | StringBuilder |
items | Object[] |
separator | String |
public static void asStringOn(StringBuilder sb, Object[] items, String separator)
//package com.java2s; /**/*from w w w. ja v a 2s .c o m*/ * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ import java.util.Iterator; public class Main { /** * Copies the elements returned by the iterator onto the string buffer each * delimited by the separator. * * @param sb * StringBuffer * @param iter * Iterator * @param separator * String */ public static void asStringOn(StringBuffer sb, Iterator<?> iter, String separator) { if (!iter.hasNext()) { return; } sb.append(iter.next()); while (iter.hasNext()) { sb.append(separator); sb.append(iter.next()); } } /** * Copies the array items onto the string builder each delimited by the * separator. Does nothing if the array is null or empty. * * @param sb * StringBuilder * @param items * Object[] * @param separator * String */ public static void asStringOn(StringBuilder sb, Object[] items, String separator) { if (items == null || items.length == 0) { return; } sb.append(items[0]); for (int i = 1; i < items.length; i++) { sb.append(separator); sb.append(items[i]); } } }