Java Collections emptySet() Method with Examples Last Updated : 08 Aug, 2024 Comments Improve Suggest changes Like Article Like Report The emptySet() method is used to get the set that has no elements. This method is used in set collection. A set is a data structure that can store unique elements.Syntax:public static final <T> Set<T> emptySet() Parameters: This method will take no parameters.Return Type: It will return an empty set that is immutable.Example 1:Java program to create an empty set Java import java.util.*; public class GFG { // main method public static void main(String[] args) { // create an empty set Set<String> data = Collections.<String>emptySet(); // display System.out.println(data); } } Output[] Example 2:In this program, we are going to create an empty set and add elements to the set. This method will return an error. Java import java.util.*; public class GFG { // main method public static void main(String[] args) { // create an empty set Set<String> data = Collections.<String>emptySet(); // add 3 elements data.add("ojaswi"); data.add("ramya"); data.add("deepu"); // display System.out.println(data); } } Output:Exception in thread "main" java.lang.UnsupportedOperationException at java.util.AbstractCollection.add(AbstractCollection.java:262) at GFG.main(GFG.java:8) Comment More infoAdvertise with us Next Article Java Collections emptySet() Method with Examples O ojaswilavu8128 Follow Improve Article Tags : Java Java-Functions Java-Collections-Class Practice Tags : Java Similar Reads Java Collections emptyList() Method with Examples The emptyList() method of Java Collections returns the list with no elements. This method is immutable. That is, we can not do any modifications after creating this method. Syntax: public static final <T> List<T> emptyList() Parameters: It will not accept any parameters Return: This meth 1 min read Java Collections emptySortedSet() Method with Examples The emptySortedSet() method of Java Collections is used to get the set that has no elements. This method is used in set collection. A set is a data structure that stores unique elements in a sorted manner. Syntax: public static final <T> Set<T> emptySortedSet() Parameters: This will take 1 min read Java Collections emptyMap() Method with Examples The emptyMap() method of Java Collections is a method that is used to return an empty map such that we can not change the data in map IE it is immutable. Syntax: public static final <Key,Value> Map<Key,Value> emptyMap() where, key is the key elementvalue is the value element Parameters: 1 min read Java Collections emptyIterator() Method with Examples The emptyIterator() method of Java Collections returns an iterator with no elements. This method is immutable. That is, we can not do any modifications after creating this method. Syntax: Iterator<data_type> object = Collections.emptyIterator(); where, data_type is the type of iterator objecto 1 min read Java Collections emptySortedMap() Method with Examples The emptySortedMap() method of Java Collections is used to get a map that has no elements. A Sorted map is a data structure that can hold elements with key-value pairs in sorted order. Syntax: public static final <Key,Value> SortedMap<Key,Value> emptySortedMap() where, key is the key ele 2 min read Like