如何在 Java 中过滤字符串流并映射为小写?同时进行排序。
假如以下内容是 String 数组,我们已将其转换为 List −
Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC")现在过滤 String 流并映射为小写 −
.stream()
.filter(a-> a.startsWith("V"))
.map(String::toLowerCase)要排序,请现在使用 sorted() 并使用 forEach() 显示。
以下是过滤字符串流并映射为小写的示例 −
示例
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);
}
}输出
Vw
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP