Java Collection Remove removeAll(Collection collection, T... elementsToRemove)

Here you can find the source of removeAll(Collection collection, T... elementsToRemove)

Description

Removes all elements from the Collection .

License

Open Source License

Parameter

Parameter Description
T The type of the Collection s elements.
collection The Collection to remove from.
elementsToRemove The elements to remove.

Return

true if the changed as result of this call.

Declaration

public static <T> boolean removeAll(Collection<T> collection, T... elementsToRemove) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Karlsruhe Institute of Technology, Germany
 *                    Technical University Darmstadt, Germany
 *                    Chalmers University of Technology, Sweden
 * All rights reserved. This program and the accompanying materials
 * are 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:/*from ww w . j  a v  a 2  s  . c  o m*/
 *    Technical University Darmstadt - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.util.Collection;

public class Main {
    /**
     * Removes all elements from the {@link Collection}. 
     * @param <T> The type of the {@link Collection}s elements.
     * @param collection The {@link Collection} to remove from.
     * @param elementsToRemove The elements to remove.
     * @return {@code true} if the {@link Collection} changed as result of this call.
     */
    public static <T> boolean removeAll(Collection<T> collection, T... elementsToRemove) {
        if (collection != null && elementsToRemove != null) {
            boolean result = false;
            for (T toAdd : elementsToRemove) {
                result = collection.remove(toAdd) || result;
            }
            return result;
        } else {
            return false;
        }
    }
}

Related

  1. removeAll(Collection c, Object e)
  2. removeAll(Collection c, T... array)
  3. removeAll(Collection c, T... array)
  4. removeAll(Collection ret, Object[] elements)
  5. removeAll(Collection collection, Collection remove)
  6. removeAll(Collection left, Collection right)
  7. removeAll(Collection source, Collection remove)
  8. removeAll(final Collection c, final Object... array)
  9. removeAll(final Collection collection, final Collection remove)

  10. HOME | Copyright © www.java2s.com 2016