Java: Useful ways to work with data
This is a continuation of the previous article. Since there is an additional dependency, this article could not be classified as using java streams. Check it out here: https://medium.com/@theoneamin/useful-java-streams-d48266effe59
List<property> from list of object
For example if we have a list of user objects, we can get a list of the usernames by using map().
This what the result would look like.
Filter list by condition
If we add the property age to our user object from above, we can use filter() to only get a list of users that match the age condition we set. For example, if we want a list of users over the age of 18, we can:
The result would look like this:
Divide a list into smaller chunks
We can partition a list into a list of list and we can set the max size for the smaller lists. This may be useful if you want to write to the database in chunks, or any other use case you may have.