Java Collection Tutorial - Java Collections.emptySet()


Collections.emptySet() has the following syntax.

public static final <T> Set <T> emptySet()


In the following code shows how to use Collections.emptySet() method.

import java.util.Collections;
import java.util.Set;
/*from   ww w .  j av a 2s  .c  o  m*/
public class Main {
   public static void main(String args[]) {
      // create an empty set    
      Set emptyset = Collections.emptySet();
      System.out.println("Created empty immutable set: "+emptyset);  
      // try to add elements

The code above generates the following result.