Java Collections emptySortedMap() Method with Examples Last Updated : 03 Jan, 2022 Comments Improve Suggest changes 1 Likes Like Report 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 elementvalue is the value element Parameters: This method does not take any parameters. Return Type: It will return an empty sorted map that is immutable. Example 1: Java program to create an empty sorted map. Java import java.util.*; public class GFG { // main method public static void main(String[] args) { // create an empty sorted map SortedMap<String, String> data = Collections.emptySortedMap(); // display System.out.println(data); } } Output{} Example 2: In this program, we are going to create an empty sorted map and add elements to the map. This method will return an error. Java import java.util.*; public class GFG { // main method public static void main(String[] args) { // create an empty sorted map SortedMap<String, String> data = Collections.emptySortedMap(); // add 3 elements data.put("1", "ojaswi"); data.put("2", "ramya"); data.put("3", "deepu"); // display System.out.println(data); } } Output: Exception in thread "main" java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableMap.put(Collections.java:1459) at GFG.main(GFG.java:10) Example 3: Java import java.util.*; public class GFG { // main method public static void main(String[] args) { // create an empty sorted map SortedMap<Integer, Integer> data = Collections.emptySortedMap(); // add 3 elements data.put(1, 34); data.put(2, 45); data.put(3, 56); // display System.out.println(data); } } Output: Exception in thread "main" java.lang.UnsupportedOperationException at java.util.Collections$UnmodifiableMap.put(Collections.java:1459) at GFG.main(GFG.java:10) Create Quiz Comment O ojaswilavu8128 Follow 1 Improve O ojaswilavu8128 Follow 1 Improve Article Tags : Java Java-Functions Java-Collections-Class Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like