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

Immutable Set 

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 ImmutableSet class. It returns an immutable set implementation which doesn't allow null elements.

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

import java.util.Arrays;
import java.util.List;

import com.google.common.collect.ImmutableSet;

public class ImmutableSetTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    ImmutableSet<String> stringSet = ImmutableSet.of("ONE""TWO""THREE""FOUR");
    System.out.println(stringSet);
    
    List<Integer> ints = Arrays.asList(1223334444);
    ImmutableSet<Integer> intSet = ImmutableSet.copyOf(ints.iterator());
    System.out.println(intSet);
  }

}
   

It gives the following output,
[ONE, TWO, THREE, FOUR]
[1, 2, 3, 4]



 
  


  
bl  br