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;
// w w w. j av a2 s .c om
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.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »