Most efficient way to get the last element of a stream

Do a reduction that simply returns the current value:

Stream<T> stream; T last = stream.reduce((a, b) -> b).orElse(null);
posted @ 2017-05-12 11:35  等风来。。  Views(159)  Comments(0Edit  收藏  举报
------------------------------------------------------------------------------------------------------------ --------------- 欢迎联系 x.guan.ling@gmail.com--------------- ------------------------------------------------------------------------------------------------------------