Here you can find the source of toString(Collection> collection, int maxLen)
Parameter | Description |
---|---|
collection | a parameter |
maxLen | a parameter |
public static String toString(Collection<?> collection, int maxLen)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Iterator; public class Main { /**/* w w w. j a v a 2s.c o m*/ * Converts given collection to string of given maximum count of items. * * @param collection * @param maxLen * @return */ public static String toString(Collection<?> collection, int maxLen) { StringBuilder builder = new StringBuilder(); builder.append("["); int i = 0; for (Iterator<?> iterator = collection.iterator(); iterator.hasNext() && i < maxLen; i++) { if (i > 0) builder.append(", "); builder.append(iterator.next()); } builder.append("]"); return builder.toString(); } }