qq_大脸猫爱吃小鱼头_0
2020-02-20 17:44
public static void main(String[] args) {
Stream<String> stream = Stream.of("1", "2", "3");
// 这里的toArray()方法需要传入一个IntFunction,可是String[]::new 跟int一点关系都没有
String[] strArray = stream.toArray(String[]::new);
}
// 这里的toArray()方法需要传入一个IntFunction,可是String[]::new 跟int一点关系都没有,怎么理解?
String[]::new means size -> new String[size].
https://stackoverflow.com/questions/44310226/what-does-stringnew-mean
Returns an array containing the elements of this stream, using the
* provided {@code generator} function to allocate the returned array
返回一个包含此流元素的数组,使用提供的函数来分配返回的数组
@param generator a function which produces a new array of the desired
* type and the provided length
生成所需类型和提供长度的新数组的函数String[]::new ,ctrl+鼠标左击 ::
你进去就是IntFunction接口。
stream01.toArray(Person[]::new); 改成Person类也可以
同问,还是没理解
@param generator a function which produces a new array of the desired type and the provided length
产生所需类型和所提供长度的新数组的函数
一课掌握Lambda表达式语法及应用
6618 学习 · 58 问题
相似问题