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

Sets Intersection 

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.intersection() API. It returns an unmodifiable view of the intersection of two sets.

File Name  :  
com/bethecoder/tutorials/guava/collection_tests/SetsIntersectionTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
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 SetsIntersectionTest {

  /**
   @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.intersection(stringSet, stringSet2);
    System.out.println(resultSet);
  }

}
   

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


                    Print

   



Books Recommendation

 
 
bl  br