Java Collections emptySortedSet() Method21 Mar 2025 | 1 min read The emptySortedSet() method of Java Collections class is used to get the sorted Set that has no elements. These empty Set are immutable in nature. SyntaxFollowing is the declaration of emptySortedSet() method: ParameterThis method does not accept any parameter. ReturnsThe emptySortedSet() method returns an empty sorted Set. ExceptionsNA Compatibility VersionJava 1.8 and above Example 1Output: Empty Sorted Set: [] Example 2Output: Created empty immutable Sorted Set: []Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.CollectionsEmptySortedSetExample2.main(CollectionsEmptySortedSetExample2.java:9) Example 3Output: Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.CollectionsEmptySortedSetExample3.main(CollectionsEmptySortedSetExample3.java:8) Next TopicJava Collections Class |
Java Collections Method The is a method of Java Collections class which returns a dynamically typesafe view of the specified collection. 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 method of Java Collections class returns an empty map which is immutable. Syntax Following is the declaration of method: public static final <K,V> Map<K,V> Parameter This method does not accept any parameter. Returns The method returns an empty immutable Map. Exceptions NA Compatibility Version Java 1.5 and...
1 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 sorted map. Syntax Following is the declaration of method: public static <K,V> SortedMap<K,V> checkedSortedMap(SortedMap<K,V> m, Class<K> keyType, Class<V> valueType) Parameter Parameter Description Required/Optional m It is the...
3 min read
Java Collections Method The method of Java Collections class is used to get the number of elements in the specified collection equal to the specified object. Syntax Following is the declaration of method: public static int frequency(Collections<?> c, Object obj) Parameter Parameter Description Required/Optional c It is the collection in which to...
2 min read
Java Collections Method The is a method of Java Collections class which returns a dynamically typesafe view of the specified list. 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>...
3 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 rotate the elements in the specified list by a given distance. Syntax Following is the declaration of method: public static void rotate(List<?> list, int distance) Parameter Parameter Description Required/Optional list It is the list which will be rotated. Required distance It is...
3 min read
Java Collections Method The method of Java Collections class returns an empty sorted map which is immutable. Syntax Following is the declaration of method: public static final <K,V> SortedMap<K,V> Parameter This method does not accept any parameter. Returns The method returns an empty immutable Sorted Map. Exceptions NA Compatibility Version Java 1.8...
1 min read
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified navigable map. Syntax Following is the declaration of method: public static <K,V> NavigableMap<K,V> unmodifiableNavigableMap(NavigableMap<? extends K, ? extends K> m) Parameter Parameter Description Required/Optional m It is the navigable map for which an...
2 min read
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
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