Input: N = 5 Output:  Input: N = GeeksForGeeks Output: [GeeksForGeeks]
- Get the value N
- Generate the Stream using generate() method
- Set the size of the List to be created as 1 using limit() method
- Pass the value to be mapped using map() method
- Convert the generated stream into List using Collectors.toList() and return it by collecting using collect() method
Below is the implementation of the above approach:
List with element 1024:  List with element GeeksForGeeks: [GeeksForGeeks]
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Initialize a list in a single line with a specified value
- Initialize a static Map using Stream in Java
- Initialize a static Map using Java 9 Map.of()
- Initialize a static Map in Java using Double Brace Initialization
- Character Stream Vs Byte Stream in Java
- Difference between Stream.of() and Arrays.stream() method in Java
- Initialize an ArrayList in Java
- Initialize HashMap in Java
- KeyPairGenerator initialize() method in Java with Examples
- Initialize a static map in Java with Examples
- How to Fill (initialize at once) an Array in Java?
- How to Initialize and Compare Strings in Java?
- foreach() loop vs Stream foreach() vs Parallel Stream foreach()
- Sum of list with stream filter in Java
- Program to Convert List to Stream in Java
- Program to convert a Set to Stream in Java using Generics
- Flatten a Stream of Lists in Java using forEach loop
- Flatten a Stream of Arrays in Java using forEach loop
- Flatten a Stream of Map in Java using forEach loop
- Count occurrence of a given character in a string using Stream API in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.