Java tutorial
//package com.java2s; import java.util.Collection; public class Main { public static <O> boolean safeAddAll(Collection<O> c, Collection<O> items) { try { return c.addAll(items); } catch (Throwable ex) { return false; } } /** * Used for dividing an original list into two lists. * * @param <T> * @param list * @param i * @return */ public static <O, P extends O> boolean safeAddAll(Collection<O> c, P[] items) { try { for (O item : items) { c.add(item); } return true; } catch (Throwable ex) { return false; } } }