Monday, January 26, 2015

google Sets API: Intersection and Union

import com.google.common.collect.Sets;

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

/** * Created by akhil on 1/26/2015. */public class SetsExample {


    public static void main(String args[]){

        Set<String> firstSet = new HashSet<String>();

        Set<String> secSet = new HashSet<String>();


        firstSet.add("akkhil");

        firstSet.add("kumar");

        firstSet.add("gupta");



        secSet.add("kapil");
        secSet.add("gupta");


        System.out.println("Interacion Example: Common items  in both sets"+ Sets.intersection(firstSet,secSet));

        System.out.println("Union Example: Total items  in both sets"+ Sets.union(firstSet,secSet));

    }



}

No comments:

Post a Comment