首页 > 解决方案 > 是否可以使用 int[] 创建 Foo[] ,其中 Foo 使用流将该 int 带入构造函数。爪哇 11

问题描述

基本上我有一个整数数组,我需要将其更改为一个对象数组,该数组接受一个整数作为构造函数。我只是想知道这是否可以在 java 11 中使用流。

标签: java

解决方案


int input[] = {1, 2, 3, 4, 5};
YourClass[] output = IntStream.of(input)
        .mapToObj(YourClass::new)
        .toArray(YourClass[]::new);

推荐阅读