Java Collection Tutorial - Java Collections.emptySet()








Syntax

Collections.emptySet() has the following syntax.

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

Example

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
      emptyset.add("from java2s.com");
   }    
}

The code above generates the following result.