- 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
How to filter String stream and map to lower case in Java? Perform sort as well.
Let’s say the following is String array, which we have converted to List −
Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC")
Now filter String stream and map to lower case −
.stream() .filter(a-> a.startsWith("V")) .map(String::toLowerCase)
To sort now, use the sorted() and display using forEach().
The following is an example to filter string stream and map to lowercase −
Example
import java.util.Arrays; public class Demo { public static void main(String[] args) throws Exception { Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC") .stream() .filter(a-> a.startsWith("V")) .map(String::toLowerCase) .sorted() .forEach(System.out::println); } }
Output
Vw
Advertisements