“String[]::new"是什么意思?意思是? [英] What does "String[]::new" mean?
本文介绍了“String[]::new"是什么意思?意思是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在学习如何使用流,但我在使用此方法时遇到了问题.
I'm learning how to use stream, and I get a problem with this method.
public static String[] inArray(String[] array1, String[] array2) {
return Arrays.stream(array1)
.filter(str -> Arrays.stream(array2).anyMatch(s -> s.contains(str)))
.distinct().sorted().toArray(**String[]::new**);
}
我对 String[]::new
很困惑,你能给我一个提示吗?
I'm so confused about String[]::new
, could you give me a hint?
推荐答案
String[]::new
表示 size ->new String[size]
.
当 Stream#toArray(IntFunction generator)
准备好生成一个数组,它调用 generator
并通过 (generator.apply
) 内部集合的大小,以获取一个集合来填充它.
When Stream#toArray(IntFunction<A[]> generator)
is ready to produce an array, it calls generator
and passes (generator.apply
) the size of the inner collection to get a collection to fill it up.
这篇关于“String[]::new"是什么意思?意思是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文