Here you can find the source of createCollection(Collection col)
Parameter | Description |
---|---|
col | a parameter |
public static Collection createCollection(Collection col)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/*from w w w . j a va 2s. co m*/ * Create and answer a collection that is the same type, or the closest * equivalent of col. * * @param col * @return */ public static Collection createCollection(Collection col) { Collection answer; try { answer = (Collection) col.getClass().newInstance(); } catch (Exception e) { if (col instanceof List) { answer = new ArrayList(); } else if (col instanceof SortedSet) { answer = new TreeSet(); } else if (col instanceof Set) { answer = new HashSet(); } else { answer = new ArrayList(); // should this throw an exception? } } return answer; } }