我们可以先来看一下这个IntFunction接口源码
@FunctionalInterface
public interface IntFunction<R> {
/**
* Applies this function to the given argument.
*
* @param value the function argument
* @return the function result
*/
R apply(int value);
}
下面我们使用一段简单的程序来使用一下这个接口
Map<Date, String> map = new HashMap<>(3);
map.put(new Date(), "1");
map.put(new Date(), "2");
map.put(new Date(), "3");
Date[] dates = map.keySet().toArray(Date[]::new);
上面的代码就是简单地把map中的key用数组收集起来了。我们需要深入一点再看一下这个toArray()方法:
default <T> T[] toArray(IntFunction<T[]> generator) {
return toArray(generator.apply(0));
}
我们再一下API文档:

Params:
generator – a function which produces a new array of the desired type and the provided length