在 Java 中將字元陣列轉換為 IntStream
假設我們有以下字元陣列
Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };要將以上字元陣列轉換到 IntStream
IntStream stream = Stream.of(arr).flatMapToInt(IntStream::of);
為此我們使用了 flatMapToInt() 方法。
以下是在 Java 中將字元陣列轉換為 IntStream 的示例
示例
import java.util.stream.*;
public class Main {
public static void main(String[] args) {
Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };
System.out.println("The character array = ");
for (char value : arr) {
System.out.println("Value = " + value);
}
IntStream stream = Stream.of(arr).flatMapToInt(IntStream::of);
System.out.println("
Character Array to IntStream = ");
stream.forEach(System.out::println);
}
}輸出
The character array = Value = V Value = e Value = h Value = i Value = c Value = l Value = e Character Array to IntStream = 86 101 104 105 99 108 101
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP