The toList() method of Collectors Class is a static (class) method. It returns a Collector Interface that gathers the input data onto a new list. This method never guarantees type, mutability, serializability, or thread-safety of the returned list but for more control toCollection(Supplier) method can be used. This is an un-ordered collector.
public static Collector<T, ?, R> toList()
- T: The type of the input elements.
- Interface Collector<T, A, R>: A mutable reduction operation that accumulates input elements into a mutable result container, optionally transforming the accumulated result into a final representation after all input elements have been processed. Reduction operations can be performed either sequentially or in parallel.
- T: The type of input elements to the reduction operation.
- A: The mutable accumulation type of the reduction operation.
- R: The result type of the reduction operation.
- toList():- Static method of Collectors class and returns a Collector interface object used to store a group of data onto a list. The Collectors class is under the java.util.streams package.
Return Value: This method returns a Collector which collects all the input elements into a List, in encounter order
Below are the examples to illustrate toList() method in Java:
[Geeks, for, GeeksforGeeks, Geeks Classes]
[1, 2, 3, 4]
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Collectors groupingBy() method in Java with Examples
- Collectors toMap() method in Java with Examples
- Collectors collectingAndThen() method in Java with Examples
- Java 8 Streams | Collectors.joining() method with Examples
- Collectors toSet() in Java with Examples
- Java 8 | Collectors counting() with Examples
- Java | Collectors averagingDouble() with Examples
- Java 8 | Collectors averagingInt() with Examples
- Java | Collectors averagingLong (ToLongFunction mapper) with Examples
- Collectors partitioningBy() method in Java
- Java | Collectors maxBy(Comparator comparator) with Examples
- Java | Collectors minBy(Comparator comparator) with Examples
- JavaTuple toList() method
- Java Stream | Collectors toCollection() in Java
- Types of JVM Garbage Collectors in Java with implementation details
- Java lang.Long.reverse() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
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.