Java Collection Add addTo(E element, C collection)

Here you can find the source of addTo(E element, C collection)

Description

Adds the given element to the given collection.

License

Open Source License

Parameter

Parameter Description
element the element to add
collection the collection to add to

Declaration

public static <C extends Collection<E>, E> C addTo(E element, C collection) 

Method Source Code

//package com.java2s;
/******************************************************************************* 
 * Copyright (c) 2014 Red Hat, Inc. /*from  www.  jav a 2 s . c  o  m*/
 * Distributed under license by Red Hat, Inc. All rights reserved. 
 * This program is made available under the terms of the 
 * Eclipse Public License v1.0 which accompanies this distribution, 
 * and is available at http://www.eclipse.org/legal/epl-v10.html 
 * 
 * Contributors: 
 * Red Hat, Inc. - initial API and implementation 
 ******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * Adds the given element to the given collection.
     * 
     * @param element the element to add
     * @param collection the collection to add to
     * @return
     */
    public static <C extends Collection<E>, E> C addTo(E element, C collection) {
        collection.add(element);
        return collection;
    }
}

Related

  1. addPrefix(Collection values, String prefix)
  2. addPreviousTags(int index, String[] prevTags, int prevTagsToAdd, Collection targetCol)
  3. addRange(Collection c, int start, int to, int step)
  4. addSafe(final Collection collection, T element)
  5. addTo(Collection l, Object... os)
  6. addTo(Map> map, K key, V value)
  7. addToCollection(C collection, E... elements)
  8. addToCollection(Collection collection, final T value)
  9. addToCollection(Collection collection, T obj)