Here you can find the source of addToCollection(Collection
Parameter | Description |
---|---|
collection | Collection into which the value is added into; can be null |
value | Value of type <T>; can be null |
public static <T> void addToCollection(Collection<T> collection, final T value)
//package com.java2s; //License from project: Apache License import java.util.Collection; public class Main { /**//from w w w. j a va2s . c o m * Adds value to the {@link Collection}. The value of type <T> is added to * the {@link Collection} if the {@link Collection} or the value are not * null. If {@link Collection#add(Object)} throws * {@link IllegalStateException} it is caught and silently ignored. * * @param collection * {@link Collection} into which the value is added into; can be * null * @param value * Value of type <T>; can be null */ public static <T> void addToCollection(Collection<T> collection, final T value) { if (collection != null && value != null) { try { collection.add(value); } catch (IllegalStateException e) { // Silently fail } } } }