Here you can find the source of toString(Iterable c, String delim, String prefix, String suffix)
@SuppressWarnings("unchecked") public static String toString(Iterable c, String delim, String prefix, String suffix)
//package com.java2s; /* /* ww w.j av a2s. co m*/ * @(#)StringUtil.java 1.0 2004-10-11 * * Copyright 2005 UFIDA Software Co. Ltd. All rights reserved. * UFIDA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.Iterator; public class Main { public static String toString(Object[] arr) { return toString(arr, ","); } @SuppressWarnings("unchecked") public static String toString(Object value, String delim) { if (value instanceof String) { return (String) value; } else { if (value.getClass().isArray()) { return toString((Object[]) value, delim); } else if (value instanceof Iterable) { return toString((Iterable) value, delim); } else { return value.toString(); } } } @SuppressWarnings("unchecked") public static String toString(Iterable c, String delim, String prefix, String suffix) { if (c == null) { return "null"; } StringBuffer sb = new StringBuffer(); Iterator it = c.iterator(); int i = 0; while (it.hasNext()) { if (i++ > 0) { sb.append(delim); } sb.append(prefix + it.next() + suffix); } return sb.toString(); } @SuppressWarnings("unchecked") public static String toString(Iterable c, String delim) { return toString(c, delim, "", ""); } public static String toString(Object value) { return toString(value, ","); } public static String toString(Object[] arr, String delim) { if (arr == null) { return "null"; } else { StringBuffer sb = new StringBuffer(); for (int i = 0; i < arr.length; i++) { if (i > 0) sb.append(delim); sb.append(arr[i]); } return sb.toString(); } } }