- 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
Java Program to Map String list to lowercase and sort
Let’s say the following is our String List −
List list = new ArrayList<>(); list.add("ABC"); list.add("CDE"); list.add("GHI"); list.add("MNO"); list.add("GWE"); list.add("WDF"); list.add("JYH"); list.add("TYU");
Map String List to lowercase −
list .stream() .map(String::toLowerCase)
After that, perform sorting −
sorted((val1, val2) -> val2.compareTo(val1))
The following is an example to Map string list to lowercase and sort −
Example
import java.util.ArrayList; import java.util.List; public class Demo { public static void main(final String[] args) { List list = new ArrayList<>(); list.add("ABC"); list.add("CDE"); list.add("GHI"); list.add("MNO"); list.add("GWE"); list.add("WDF"); list.add("JYH"); list.add("TYU"); list .stream() .map(String::toLowerCase) .sorted((val1, val2) -> val2.compareTo(val1)) .forEach(System.out::println); } }
Output
wdf tyu mno jyh gwe ghi cde abc
Advertisements