Java Collections emptySortedMap() Method21 Mar 2025 | 1 min read The emptySortedMap() method of Java Collections class returns an empty sorted map which is immutable. SyntaxFollowing is the declaration of emptySortedMap() method: ParameterThis method does not accept any parameter. ReturnsThe emptySortedMap() method returns an empty immutable Sorted Map. ExceptionsNA Compatibility VersionJava 1.8 and above Example 1Output: Created Empty Sorted Map: {} Example 2Output: Created Empty Sorted Map: {} Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453) at myPackage.CollectionsEmptySortedMapExample2.main(CollectionsEmptySortedMapExample2.java:9) Example 3Output: Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453) at myPackage.CollectionsEmptySortedMapExample3.main(CollectionsEmptySortedMapExample3.java:8) Next TopicJava Collections Class |
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified collection. If any attempt occurs to modify the returned collection whether direct or via its iterator, result in an UnsupportedOperationException. Syntax Following is the declaration of ...
2 min read
Java Collections Method The is a Java Collections class method which returns the minimum value for the given inputs. There is two different types of Java method which can be differentiated depending on its parameter. These are: Java Collections min(coll) Method Java Collections min(coll, comp)...
3 min read
Java Collections Method The method of Java Collections class is used to get a synchronized (thread-safe) navigable map backed by the specified navigable map. Syntax Following is the declaration of method: public static <K,V> NavigableMap<K,V> synchronizedNavigableMap(NavigableMap<K,V> m) Parameter Parameter Description Required/Optional m It is the navigable map which will be wrapped in...
2 min read
Java Collections Method The method of Java Collections class is used to get an Iterator that has no elements. Syntax Following is the declaration of method: Parameter This method does not accept any parameter. Returns The method returns an empty Iterator. Exceptions NA Compatibility Version Java 1.7 and above Example 1 import java.util.*; public class...
2 min read
Java Collections Method The method of Java Collections class is used to get an immutable map, mapping only the specified key to the specified value. Syntax Following is the declaration of method: public static <K,V> Map<K,V> singletonMap(K key, V value) Parameter Parameter Description Required/Optional key It is the key which will...
2 min read
Java Collections Method The is a method of Java Collections class which returns a dynamically typesafe view of the specified Queue. If an element inserted of the wrong type, it will result in an immediate ClassCastException. Syntax Following is the declaration of method: public static <E>...
2 min read
Java Collections Method The is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Map. If any attempt of insert mapping whose key or value has the wrong type, it will result in...
3 min read
Java Collections Method The is a Java Collections class method which returns the maximum value for the given inputs. All elements in the collection must implement the Comparable interface. There is two different types of Java method which can be differentiated depending on...
3 min read
Java Collections Method The method of Java Collections class is used to reverse the order of the elements in the specified list. Syntax Following is the declaration of method: public static void reverse(List<?> list) Parameter Parameter Description Required/Optional list It is the list whose elements are to be reversed. Required Returns The method does...
2 min read
Java Collections Method The method of Java Collections class is used to get the starting position of the first occurrence of the specified target list within the specified source list. It returns -1 if there is no such occurrence in the specified list. Syntax Following is...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India