Initialize a list in a single line with a specified value
Given a value N, the task is to create a List having this value N in a single line in Java using Collection Framework only.
Input: N = 5 Output:  Input: N = GeeksForGeeks Output: [GeeksForGeeks]
- Get the value N
- Generate a Collection with a single value N using Collections.nCopies() method
- Store this collection as a List.
Below is the implementation of the above approach:
List with element 1024:  List with element GeeksForGeeks: [GeeksForGeeks]
My Personal Notes arrow_drop_up
Please Login to comment...