Java Collection Tutorial - Java Set.addAll(Collection <? extends E > c)








Syntax

Set.addAll(Collection <? extends E > c) has the following syntax.

boolean addAll(Collection <? extends E > c)

Example

In the following code shows how to use Set.addAll(Collection <? extends E > c) method.

//  w  ww . j a  v a 2  s.c  om

import java.util.HashSet;
import java.util.Set;

public class Main {
  public static void main(String args[]) {
    Set set = new HashSet();
    Set set2 = new HashSet();
    StringBuffer buff1 = new StringBuffer("Irish Setter");
    StringBuffer buff2 = new StringBuffer("Irish Setter");
    set.add(buff1);
    set2.add(buff2);
    System.out.println(set.addAll(set2));
    System.out.println(set.addAll(set));
  }
}

The code above generates the following result.