Make Selenium Easy

How To Sort List In Ascending & Descending Order Using Java Stream API?

Introduction

Stream API feature was introduced in Java 8 but it is still confusing for many and also many have not even used it a single time. I will try to explain Java Stream concepts with simple examples in Learn Stream API in Java with Examples series.

In this post, we will learn to Sort List In Ascending & Descending Order Using Java Stream API i.e. sorted() method.

YouTube Tutorials

If you want to learn from a video tutorial then please refer to the below video –

Sort List In Ascending & Descending Order Using Java Stream API

Java stream provides a method sorted() which can sort List in ascending and descending order without you to write any complex logic. By default sorting() method sorts the list in ascending order. If we want to sort in descending order we need to pass Comparator.reverseOrder() in sorted() method as a parameter.

Java Program

Output

GitHub Repo Link

https://github.com/amod-mahajan/MSE_LearnJavaStreamsWithExamples.git

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe to my YouTube channel.
#ThanksForReading
#HappyLearning

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

How To Sort List In Ascending & Descending Order Using Java Stream API?

by Amod Mahajan time to read: 1 min
0
%d bloggers like this: