How to Create Empty Set with Collections Class in Java


In this example, we will create an empty set using theemptySet()method.

Source Code

package com.beginner.examples;

import java.util.Collections;
import java.util.Set;
 
public class EmptySetExample {
 
    public static void main(String a[]){
        // use emptySet()
        Set set = Collections.emptySet();
        System.out.println("Set: " + set);
    }
}

Output:

Set: []

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments