Java Collections Java Java API
Class:
java.util.Collections
Method:
@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c,
T... elements)
Adds all of the specified elements to the specified collection.
This method loops through each specified element and add to the collection individually:
boolean result = false; for (T element : elements) result |= c.add(element); return result;
Examples
package com.logicbig.example.collections;
import java.util.Collections; import java.util.HashSet; import java.util.Set;
public class AddAllExample {
public static void main(String... args) { Set<Integer> set = new HashSet<>(); boolean b = Collections.addAll(set, 1, 2, 3, 4, 5); System.out.println(b); System.out.println(set); } }
Outputtrue [1, 2, 3, 4, 5]
|
|