From the course: Data Science for Java Developers
Unlock this course with a free trial
Join today to access over 22,500 courses taught by industry experts.
Collecting - Java Tutorial
From the course: Data Science for Java Developers
Collecting
- [Instructor] Okay, so we've seen map and filters so far. The next method we're going to take a look at is a method that we've actually seen before and that is this collect method here. Cause so far we've been mainly using the collect method almost exclusively in fact, to convert a stream back into a list. But in fact, we can actually use the collect method for a lot of different purposes, depending on what we need it for. So one example of this is instead of converting to a list we could convert our stream to a set. So let's say that instead of having our long words list be a list. We wanted it to be a set. We could basically just change that like that. And instead of saying collectors.tolist we would say collectors.toset. And just as a side note here the collector's class here has a lot of static methods like this that allow us to really change the functionality of this collect method and the type that it returns.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.