Collections singletonList null
Ngày đăng:
02/01/2022
Trả lời:
0
Lượt xem:
67
Collections singletonList() method in Java with ExamplesThe singletonList() method of java.util.Collections class is used to return an immutable list containing only the specified object. The returned list is serializable. This list will always contain only one element thus the name singleton list. When we try to add/remove an element on the returned singleton list, it would give UnsupportedOperationException. Syntax: Parameters: This method takes the object o as a parameter to be stored in the returned list.Return Value: This method returns an immutable list containing only the specified object. Below are the examples to illustrate the singletonList() method Example 1: Java
Output
singletonList : [E]
Example 2: Java
Output
singletonList : [20]
Article Tags :
Java
Java - util package Java-Collections Java-Functions Practice Tags :
Java Java-Collections
Read Full Article
|