装箱数组是以对象的形式定义的数组,而不是以基元的形式定义的数组。
以下是将装箱数组转换为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]