Java Utililty Methods Collection Add

List of utility methods to do Collection Add

Description

The list of methods to do Collection Add are organized into topic(s).

Method

voidadd(Collection c, Object o)
add
c.add(o);
voidadd(Collection collection, T object)
add
collection.remove(object);
collection.add(object);
booleanadd(Collection collection, T object)
Add a value to a collection provided both the collection and the value are not null.
return object != null && collection != null && collection.add(object);
Collectionadd_all(Collection target, Collection source)
adall
((Collection<T>) target).addAll(source);
return target;
voidadd_news(Collection target, Collection to_add)
adnews
for (Iterator<? extends T> it = to_add.iterator(); it.hasNext();) {
    T element = it.next();
    if (!target.contains(element))
        target.add(element);
CaddAll(C collection, Iterable add)
Adds all elements in the add Iterable to the collection Collection.
if (add instanceof Collection) {
    collection.addAll((Collection<E>) add);
} else {
    for (E a : add) {
        collection.add(a);
return collection;
...
CaddAll(C collection, T... elements)
add All
collection.addAll(Arrays.asList(elements));
return collection;
voidaddAll(Collection collection, Iterator iterator)
Adds all elements in the iteration to the given collection.
while (iterator.hasNext()) {
    collection.add(iterator.next());
voidaddAll(Collection collection, Object[] array)
Add all elements from the supplied array to the specified collection.
for (Object obj : array) {
    collection.add(obj);
voidaddAll(Collection collection, Object[] array)
add All
for (int i = 0, max = array.length; i < max; i++) {
    collection.add(array[i]);