Here you can find the source of getCollectionPreview(final Collection> collection, int previewSize)
Parameter | Description |
---|---|
collection | the collection. |
previewSize | the number of elements to enumerate. |
public static String getCollectionPreview(final Collection<?> collection, int previewSize)
//package com.java2s; import java.util.*; public class Main { /**//w w w .j a v a 2 s . c o m * Separator string for lists. */ public static final String LIST_SEPARATOR = ","; /** * Generates a string that enumerates just the first elements of a collection (a preview). * * @param collection the collection. * @param previewSize the number of elements to enumerate. * @return a string with the first <i>previewSize</i> elements of the collection. */ public static String getCollectionPreview(final Collection<?> collection, int previewSize) { final Iterator<?> it = collection.iterator(); final StringBuilder buffer = new StringBuilder(); if (it.hasNext()) { buffer.append('[').append(it.next().toString()); for (; previewSize > 0 && it.hasNext(); --previewSize) buffer.append(LIST_SEPARATOR).append(' ').append(it.next().toString()); if (it.hasNext()) buffer.append(" ... "); buffer.append(']'); } return buffer.toString(); } }