Java tutorial
//package com.java2s; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; public class Main { private static Collection getEmpty(Collection collection) { try { return (Collection) collection.getClass().newInstance(); } catch (Exception e) { if (collection instanceof List) { return new ArrayList(); } else { return new HashSet(); } } } }