{"id":66872,"date":"2025-05-03T13:08:13","date_gmt":"2025-05-03T05:08:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66872\/"},"modified":"2025-05-03T13:08:13","modified_gmt":"2025-05-03T05:08:13","slug":"java%e6%80%8e%e4%b9%88%e5%88%a4%e6%96%ad%e4%ba%8c%e7%bb%b4%e6%95%b0%e7%bb%84%e6%98%af%e5%90%a6%e4%b8%ba%e9%9b%b6-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66872\/","title":{"rendered":"Java\u600e\u4e48\u5224\u65ad\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6"},"content":{"rendered":"<blockquote><p>\n  \u904d\u5386\u6570\u7ec4\uff0c\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002\u4f7f\u7528 arrays.stream() \u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\u5e76\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111713514179382.jpg\" class=\"aligncenter\" title=\"Java\u600e\u4e48\u5224\u65ad\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6\u63d2\u56fe\" alt=\"Java\u600e\u4e48\u5224\u65ad\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5224\u65ad Java \u4e2d\u7684\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5224\u65ad\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5faa\u73af\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20<\/strong><\/p>\n<p>\u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\u7684\u6bcf\u4e00\u884c\u548c\u6bcf\u4e00\u5217\uff0c\u5e76\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>int[][] array = new int[3][4];\n\nboolean isZero = true;\nfor (int i = 0; i &lt; array.length; i++) {\n    for (int j = 0; j &lt; array[i].length; j++) {\n        if (array[i][j] != 0) {\n            isZero = false;\n            break;\n        }\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Arrays.stream()<\/strong><\/p>\n<p>\u4f7f\u7528 Arrays.stream() \u53ef\u4ee5\u5c06\u4e8c\u7ef4\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\uff0c\u5e76\u4f7f\u7528 allMatch() \u65b9\u6cd5\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>int[][] array = new int[3][4];\n\nboolean isZero = Arrays.stream(array).allMatch(row -&gt; Arrays.stream(row).allMatch(value -&gt; value == 0));<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u6240\u6709\u5143\u7d20\u90fd\u4e3a\u96f6\uff0c\u5219 isZero \u4f1a\u88ab\u8bbe\u7f6e\u4e3a true\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u600e\u4e48\u5224\u65ad\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u904d\u5386\u6570\u7ec4\uff0c\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002\u4f7f\u7528 arrays.stream() \u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\u5e76\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002 \u5982\u4f55\u5224\u65ad Java \u4e2d\u7684\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6 \u5728 Java \u4e2d\uff0c\u5224\u65ad\u4e8c\u7ef4\u6570\u7ec4\u662f\u5426\u4e3a\u96f6\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5faa\u73af\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20 \u904d\u5386\u4e8c\u7ef4\u6570\u7ec4\u7684\u6bcf\u4e00\u884c\u548c\u6bcf\u4e00\u5217\uff0c\u5e76\u68c0\u67e5\u6bcf\u4e2a\u5143\u7d20\u662f\u5426\u4e3a\u96f6\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u793a\u4f8b\u4ee3\u7801\uff1a int[][] array = new int[3][4]; boolean isZero = true; for (int i = 0; i &lt; array.length; i++) { for (int j = 0; j &lt; array[i].length; j++) { if (array[i][j] != 0) { isZero = false; break; } } } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-66872","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66872","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=66872"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66872\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66872"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}