Java Collections unmodifiableList() Method21 Mar 2025 | 2 min read The unmodifiableList() method of Java Collections class is used to get an unmodifiable view of the specified list. If any attempt occurs to modify the returned list whether direct or via its iterator, results in an UnsupportedOperationException. SyntaxFollowing is the declaration of unmodifiableList() method: Parameter
ReturnsThe unmodifiableList() method returns an unmodifiable view of the specified list. ExceptionsNA Example 1Output: Unmodifiable List: [Google, Mozila FireFox, Yahoo] Unmodifiable List after adding element to the list:[Google, Mozila FireFox, Yahoo, Safari] Example 2Output: Unmodifiable List: [Google, Mozila FireFox, Yahoo] Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.UnmodifiableListExample2.main(UnmodifiableListExample2.java:9) Example 3Output: Unmodifiable list: [10, 20, 30, 40] Unmodifiable list after adding (50): [10, 20, 30, 40, 50] Next TopicJava Collections Class |
Java Collections Method The method of Java Collections class is used to swap the elements at the specified positions in the specified list. Syntax Following is the declaration of method: public static void swap(List<?> list, int i, int j) Parameter Parameter Description Required/Optional list It is the list in which we will...
2 min read
Java Collections Method The method of Java Collections class is used to return a set backed by the specified map. The resulting set displays the same ordering, concurrency, and performance characteristics as the backing map. Syntax Following is the declaration of method: public static <E> Set<E>...
2 min read
Java Collections Method The method of Java Collections class is used to get the empty navigable Set which is immutable in nature. Syntax Following is the declaration of method: public static <E> NavigableSet<E> Parameter This method does not accept...
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 method of Java Collections class is used to get an array list containing the elements returned by the specified enumeration in the order in which they are returned by the enumeration. Syntax Following is the declaration of method: public static <T> ArrayList<T>...
2 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 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 a synchronized (thread-safe) collection backed by the specified collection. Syntax Following is the declaration of method: public static <T> Collection<T> synchronizedCollection(Collection<T> c) Parameter Parameter Description Required/Optional c It is the collection to be "wrapped" in a synchronized collection. Required Returns The ...
2 min read
Java Collections Method The method of Java Collections class is used to get an unmodifiable view of the specified map. Syntax Following is the declaration of method: public static <K,V> Map<K,V> unmodifiableMap(Map<? extends K, ? extends K> m) Parameter Parameter Description Required/Optional m It is the map for which an unmodifiable view...
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