- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Collectors toList() method in Java 8
The toList() method of the Collectors class returns a Collector that accumulates the input elements into a new List.
The syntax is as follows −
static <T> Collector<T,?,List<T>> toList()
Here, parameter T is the type of input elements.
To work with Collectors class in Java, import the following package −
import java.util.stream.Collectors;
The following is an example to implement Collectors toList() method in Java −
Example
import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { Stream<String> stream = Stream.of("25", "40", "90", "150", "180", "220", "350"); List<String> list = stream.collect(Collectors.toList()); System.out.println("List = "+list); } }
Output
List = [25, 40, 90, 150, 180, 220, 350]
- Related Articles
- Collectors toSet() method in Java 8
- Collectors averagingLong () method in Java 8
- Collectors averagingDouble() method in Java 8
- Collectors counting() method in Java 8
- Collectors averagingInt() method in Java 8
- Collectors toCollection() method in Java 8
- Collectors maxBy() method in Java 8
- Collectors minBy() method in Java 8
- Collectors collectingAndThen() method in Java 8
- Collectors partitioningBy() method in Java 8
- Java Stream Collectors toCollection() in Java
- Collectors.joining() method in Java 8
- How to create IntSummaryStatistics from Collectors in Java?
- clone() method in Java\n
- StringJoiner add() method in Java 8

Advertisements