Collections.singleton(List): This method is available in java.util.Collections class of Java.
Syntax:
<List<E>> Set<List<E>> java.util.Collections.singleton(List<E> o)
This method takes one argument. This method returns an immutable set containing only the specified object.The returned set is serializable.
Parameters: One parameter is required for this method.
o: the sole object to be stored in the returned set.
Returns: an immutable set containing only the specified object.
Exceptions: NA
Approach
Java
import java.util.ArrayList;import java.util.Collections;import java.util.List;public class Collectionssingleton {public static void main(String[] args) {List<Integer> arrlist = new ArrayList<Integer>();arrlist.add(12);arrlist.add(56);arrlist.add(899);arrlist.add(65);arrlist.add(12);System.out.println(Collections.singleton(arrlist));}}
Output:
[[12, 56, 899, 65, 12]]
No comments:
Post a Comment