bi是binary的简写,二元的,表示两个参数
unary,一元的,表示一个参数
1.函数式接口Supplier T get(),不接收参数,有返回值
IntSupplier,int getAsInt(),不接收参数,返回一个int型结果
LongSupplier,long getAsLong(),不接收参数,返回一个long型结果
DoubleSupplier,double getAsDouble(),不接收参数,返回一个double型结果
2.函数式接口Consumer void accept(T t),接受一个参数,不返回
IntConsumer,void accept(int value),接收一个int型参数,不返回值
LongConsumer,void accept(long value),接收一个long型参数,不返回值
DoubleConsumer,void accept(double value),接收一个double型参数,不返回
3.函数式接口Function R apply(T t),接收一个参数,有返回值
IntFunction,R apply(int value),接收一个int型参数,有返回值
ToIntFunction,int applyAsInt(T value),接收一个参数,返回一个int型结果
LongFunction,R apply(long value),接收一个long型参数,有返回值
ToLongFunction,long applyAsLong(T value),接收一个参数,返回一个long型结果
DoubleFunction,R apply(double value),接收一个double型参数,有返回值
ToDoubleFunction,double applyAsDouble(T value),接收一个参数,返回一个double型结果
4.函数式接口UnaryOperator,是Function的子接口。接收一个参数,有返回值,且返回值的类型与参数类型一样
IntUnaryOperator,int applyAsInt(int operand),接收一个int型参数,返回一个int型结果
LongUnaryOperator,long applyAsLong(long operand),接收一个long型参数,返回一个long型结果
DoubleUnaryOperator,double applyAsDouble(double operand),接收一个double型参数,返回一个double型结果
5.函数式接口BiConsumer void accept(T t, U u),接收两个参数,不返回
6.函数式接口BiFunction R apply(T t, U u),接收两个参数,有返回值
ToIntBiFunction,int applyAsInt(T t, U u),接收两个参数,返回一个int型结果
ToLongBiFunction,long applyAsLong(T t, U u),接收两个参数,返回一个long型结果
ToDoubleBiFunction,double applyAsDouble(T t, U u),接收两个参数,返回一个double型结果
7.函数式接口BinaryOperator,是BiFunction的子接口。接收两个参数,有返回值,且两个参数和返回值的类型都一样
IntBinaryOperator,int applyAsInt(int left, int right),接收两个int型参数,返回一个int型结果
LongBinaryOperator,long applyAsLong(long left, long right),接收两个long型参数,返回一个long型结果
DoubleBinaryOperator,double applyAsDouble(double left, double right),接收两个double型参数,返回一个double型结果
8.函数式接口Predicate boolean test(T t),接收一个参数,返回true或者false
9.接口Stream、IntStream、LongStream、DoubleStream
接口Stream
static Stream<T> of(T... values),入参是多个同一种类型的值或者数组,返回一个Stream对象
static Stream generate(Supplier s),生成一个无穷的、无序的Stream对象
static Stream iterate(T seed, UnaryOperator<T> f),生成一个无穷的、有序的Stream对象,生成规则就好像迭代函数一样,seed是第一个元素,第二个元素是传seed进去生成的结果,第三个元素是传第二个元素进去生成的结果。。。以此类推
Stream distinct(),返回一个新的去重后的Stream对象
Stream sorted(Comparator comparator),入参是一个排序器,返回一个排好序的Stream对象
Stream map(Function mapper),入参是一个Function对象,返回一个新的Stream对象
Stream flatMap(Function mapper),和map()方法的不同需要再分析
Stream skip(long n),返回一个出去前n个元素之后的Stream对象
Stream limit(long maxSize),返回一个最多包含maxSize个元素的新的Stream对象
Stream filter(Predicate predicate),返回一个过滤后的新的Stream对象
IntStream mapToInt(ToIntFunction mapper),把一个Stream对象转换成一个IntStream对象
Optional findFirst(),返回包含第一个元素的Optional对象
long count(),返回Stream对象包含的元素的个数
Object[] toArray(),返回一个数组,可转换至具体类型的数组
void forEach(Consumer action),传入一个Consumer对象
Optional max(Comparator comparator),返回Stream对象包含的最大的元素,怎么算大,由传入的Comparator对象决定
collect(Collector collector),传入一个Collector对象,Collector对象可以调用Collectors的各种静态方法生成,如toList(),toCollection(Supplier collectionFactory),toSet(),reducing()的三个重载、joining()的三个重载、groupingBy()的三个重载等等,还有好多使用的方法
接口IntStream
static IntStream range(int startInclusive, int endExclusive),返回一个IntStream对象,元素包含第一个参数,不包含第二个参数
static IntStream rangeClosed(int startInclusive, int endInclusive),返回一个IntStream对象,两边都包含
IntSummaryStatistics summaryStatistics(),返回一个IntSummaryStatistics对象,进而可以得到最大值、最小值这些。
int sum(),求和
reduce()方法,有2个重载
第1个重载,OptionalInt reduce(IntBinaryOperator op),入参是个IntBinaryOperator对象,返回一个OptionalInt对象
第2个重载,int reduce(int identity, IntBinaryOperator op),第一个参数是个int值,第二个参数是个IntBinaryOperator对象,返回一个int型结果
10.final类Optional、OptionalInt
Optional
T get(),如果值存在,返回原值,否则抛出NoSuchElementException异常
T orElse(T other),如果值存在,返回原值,否则返回传入的值
void ifPresent(Consumer consumer),如果值存在的话,就处理,否则什么都不做。
OptionalInt
int getAsInt(),如果值存在,返回原值,否则抛出NoSuchElementException异常
int orElse(int other),如果值存在,返回原值,否则返回传入的值
void ifPresent(IntConsumer consumer),如果值存在的话,就处理,否则什么都不做。
11.IntSummaryStatistics,IntConsumer的实现类
LongSummaryStatistics,LongConsumer的实现类
DoubleSummaryStatistics,DoubleConsumer的实现类
用于汇总统计的类,通过调用getMin()、getMax()、getAverage()、getCount()、getSum()实例方法获取最小值、最大值、平均值、个数、求和。