Here you can find the source of toString(Collection> collection)
Parameter | Description |
---|---|
collection | Collection |
public static String toString(Collection<?> collection)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**/* w w w . j av a2s .c o m*/ * * @param collection Collection * @return String representing given collection */ public static String toString(Collection<?> collection) { if (collection == null || collection.isEmpty()) { return ""; } StringBuilder stringBuilder = new StringBuilder("["); for (Object object : collection) { if (object instanceof Collection<?>) { stringBuilder.append(toString((Collection<?>) object)); } else { stringBuilder.append(object).append(", "); } } stringBuilder.append("]"); return stringBuilder.toString().replaceAll(", ]", "]"); } }