Here you can find the source of printElement(Collection> pCollection, boolean pAllElement)
Parameter | Description |
---|---|
pA | a parameter |
pAllElement | a parameter |
public static String printElement(Collection<?> pCollection, boolean pAllElement)
//package com.java2s; //License from project: Open Source License import java.util.Arrays; import java.util.Collection; import java.util.Iterator; public class Main { public static final String ANEMPTYSPACE = " "; /**//from w w w .java 2 s .c om * For Testing use. Output the content of the array to a string. If the all element parameter is * false, output only the first 10 elements. * * @param pArray * @param pAllElement * @return */ public static String printElement(long[] pArray, boolean pAllElement) { int size = pArray.length; if (!pAllElement && size > 10) { size = 10; } if (size != 10) { return Arrays.toString(pArray); } StringBuffer buf = new StringBuffer(); for (int i = 0; i < size; i++) { buf.append(i).append("= ").append(pArray[i]).append(ANEMPTYSPACE); } return buf.toString(); } /** * For Testing use. Output the content of the array to a string. If the all element parameter is * false, output only the first 10 elements. * * @param pArray * @param pAllElement * @return */ public static String printElement(Long[] pArray, boolean pAllElement) { int size = pArray.length; if (!pAllElement && size > 10) { size = 10; } if (size != 10) { return Arrays.toString(pArray); } StringBuffer buf = new StringBuffer(); for (int i = 0; i < size; i++) { buf.append(i).append("= ").append(pArray[i]).append(ANEMPTYSPACE); } return buf.toString(); } /** * For Testing use. Output the content of the collection to a string. If the all element * parameter is false, output only the first 10 elements. * * @param pA * @param pAllElement * @return */ public static String printElement(Collection<?> pCollection, boolean pAllElement) { int size = pCollection.size(); if (!pAllElement && size > 10) { size = 10; } StringBuffer buf = new StringBuffer(); Iterator<?> iter = pCollection.iterator(); for (int i = 0; i < size; i++) { buf.append(i).append("= ").append(iter.next()).append(ANEMPTYSPACE); } return buf.toString(); } }