Collections.unmodifiableList(List): This method is available in java.util.Collections class of Java.
Syntax:
<E> List<E> java.util.Collections.unmodifiableList(List<? extends E> list)
This method takes one argument. This method returns an unmodifiable view of the specified list.
Parameters: One parameter is required for this method.
list: the list for which an unmodifiable view is to be returned.
Returns: an unmodifiable view of the specified list.
Exceptions: NA
Approach
Java
import java.util.ArrayList;import java.util.Collections;import java.util.List;public class CollectionsunmodifiableList {public static void main(String[] args) {List<String> list = new ArrayList<String>();list.add("Hello");list.add("Java");list.add("C++");System.out.println(Collections.unmodifiableList(list));}}
Output:
[Hello, Java, C++]
No comments:
Post a Comment