【一天一坑】空数组,使用 allMatch 默认返回true

复制代码
List<Integer> list = new ArrayList<>();
boolean flag = list.stream().allMatch(e -> e > 0);
//flag = true
复制代码
/**
 * Returns whether all elements of this stream match the provided predicate.
 * May not evaluate the predicate on all elements if not necessary for
 * determining the result.  If the stream is empty then {@code true} is
 * returned and the predicate is not evaluated.
 *
 * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
 * terminal operation</a>.
 *
 * @apiNote
 * This method evaluates the <em>universal quantification</em> of the
 * predicate over the elements of the stream (for all x P(x)).  If the \* stream is empty, the quantification is said to be \<em\>vacuously \* satisfied\</em\> and is always {@code true} (regardless of P(x)).
 *
 * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,
 *                  <a href="package-summary.html#Statelessness">stateless</a>
 *                  predicate to apply to elements of this stream
 * @return {@code true} if either all elements of the stream match the
 * provided predicate or the stream is empty, otherwise {@code false}
 */
相关推荐
山西第一大怨种几秒前
我的浏览器下雨了进水了
前端·webgl
何贤1 分钟前
😲我写出了 Threejs 版城市天际线?!(官推转发🥳+ 源码分享🚀)
前端·开源·three.js
前端老鹰2 分钟前
JavaScript Array.prototype.at ():数组任意位置取值的新姿势
前端·javascript
autumnTop9 分钟前
为什么访问不了同事的服务器或者ping不通地址了?
前端·后端·程序员
weixin_4433533130 分钟前
小红书帖子评论的nodejs爬虫脚本
前端·爬虫
yzzzzzzzzzzzzzzzzz32 分钟前
HTML 常用标签介绍
前端·html
Wcy307651906634 分钟前
web前端第二次作业
前端·javascript·css
北京_宏哥35 分钟前
Python零基础从入门到精通详细教程11 - python数据类型之数字(Number)-浮点型(float)详解
前端·python·面试
waterHBO38 分钟前
css 模拟一个动画效果,消息堆叠。
前端·css
手把手入门1 小时前
★CentOS:MySQL数据备份
数据库·mysql·adb