我正在学习如何使用流,但我遇到了这种方法的问题。
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
很困惑,你能给我一个提示吗?
最佳答案
String[]::new
意味着 size -> new String[size]
.
当 Stream#toArray(IntFunction<A[]> generator)
准备好生成一个数组,它调用 generator
并传递( generator.apply
)内部集合的大小以获得一个集合来填充它。
关于java - "String[]::new"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44310226/