如何在 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