如何在Java中过滤字符串流并将其映射为小写?也执行排序。
假设以下是String数组,我们已将其转换为List-
Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC")现在过滤字符串流并映射为小写-
.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