Java 中将装箱数组转换为流的程序
装箱数组是以对象而不是基元形式定义的数组。
示例
以下是 Java 中将装箱数组转换为流的程序 -
import java.util.*; import java.util.stream.*; public class Demo { public static void main(String args[]) { String arr[] = { "Laptop", "Mobile", "Notebook", "Desktop" }; System.out.println("Array = "+ Arrays.toString(arr)); Stream<String>s = Stream.of(arr); System.out.println("Stream (array to stream) = "+ Arrays.toString(s.toArray())); } }
输出
Array = [Laptop, Mobile, Notebook, Desktop] Stream (array to stream) = [Laptop, Mobile, Notebook, Desktop]
广告