tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Google Guava > Collections > Sets Union

Sets Union 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Sets.union() API. It returns an unmodifiable view of the union of two sets.

File Name  :  
com/bethecoder/tutorials/guava/collection_tests/SetsUnionTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.guava.collection_tests;

import java.util.Set;

import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;

public class SetsUnionTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    ImmutableSet<String> stringSet = ImmutableSet.of("ONE""TWO""THREE");
    System.out.println(stringSet);
    
    ImmutableSet<String> stringSet2 = ImmutableSet.of("TWO""THREE""FOUR");
    System.out.println(stringSet2);
    
    Set<String> resultSet = Sets.union(stringSet, stringSet2);
    System.out.println(resultSet);
  }

}
   

It gives the following output,
[ONE, TWO, THREE]
[TWO, THREE, FOUR]
[ONE, TWO, THREE, FOUR]



 
  


  
bl  br