Java Collections unmodifiableSet() Method21 Mar 2025 | 2 min read The unmodifiableSet() method of Java Collections class is used to get an unmodifiable view of the specified set. SyntaxFollowing is the declaration of unmodifiableSet() method: Parameter
ReturnsThe unmodifiableSet() method returns an unmodifiable view of the specified set. ExceptionsNA Example 1Output: Initial Set: [1, 2, 3, 4, 5] Unmodifiable Set: [1, 2, 3, 4, 5] Unmodifiable Set: [1, 2, 3, 4, 5, 15] Example 2Output: Initial Set: [Facebook, Google, Instagram] Unmodifiable Set: [Facebook, Google, Instagram] Unmodifiable Set: [Facebook, Google, Instagram, Twitter] Example 3Output: Original Set: [11, 13, 17] Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.CollectionsUnmodifiableSetExample3.main(CollectionsUnmodifiableSetExample3.java:9) Next TopicJava Collections Class |
Java Collections Method The method of Java Collections class is used to get the sorted Set that has no elements. These empty Set are immutable in nature. Syntax Following is the declaration of method: public static final <E> SortedSet<E> Parameter This method does not accept any parameter. Returns The...
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 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 is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified Navigable Set. If any attempt of inserting an element whose value has the wrong type, it will through an...
2 min read
Java collection class is used exclusively with static methods that operate on or return collections. It inherits Object class. The important points about are: Java Collection class supports the polymorphic algorithms that operate on collections. Java Collection class throws a NullPointerException if the collections or class objects provided...
6 min read
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified sorted set. Syntax Following is the declaration of method: public static <T> SortedSet<T> unmodifiableSortedSet(SortedSet<T> s) Parameter Parameter Description Required/Optional s It is the sorted set for which an unmodifiable view is to...
2 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 method of Java Collections class is used to get an immutable list which contains only the specified object. Syntax Following is the declaration of method: public static <T> List<T> singletonList(T o) Parameter Parameter Description Required/Optional o It is the object which will be stored in the returned List. Required Returns The...
2 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
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
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