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 |
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