{"id":66523,"date":"2025-05-03T17:26:24","date_gmt":"2025-05-03T09:26:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66523\/"},"modified":"2025-05-03T17:26:24","modified_gmt":"2025-05-03T09:26:24","slug":"java%e6%80%8e%e4%b9%88%e5%88%a4%e6%96%ad%e4%b8%80%e4%b8%aa%e7%a9%ba%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66523\/","title":{"rendered":"java\u600e\u4e48\u5224\u65ad\u4e00\u4e2a\u7a7a\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5224\u65ad java \u4e2d\u7a7a\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u6bd4\u8f83\u957f\u5ea6\uff1a\u5982\u679c\u6570\u7ec4\u957f\u5ea6\u4e3a 0\uff0c\u5219\u6570\u7ec4\u4e3a\u7a7a\u3002\u4f7f\u7528 guava \u5e93\u7684 isempty() \u65b9\u6cd5\uff1a\u5982\u679c\u6570\u7ec4\u4e3a\u7a7a\uff0c\u5219\u8fd4\u56de true\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111605393958769.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5224\u65ad\u4e00\u4e2a\u7a7a\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5224\u65ad\u4e00\u4e2a\u7a7a\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5224\u65ad Java \u4e2d\u7a7a\u6570\u7ec4\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5224\u65ad\u4e00\u4e2a\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\u975e\u5e38\u7b80\u5355\u3002<\/p>\n<p><strong>\u65b9\u5f0f 1\uff1a\u6bd4\u8f83\u957f\u5ea6<\/strong><\/p>\n<p>\u6570\u7ec4\u7684 length \u5c5e\u6027\u8868\u793a\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002\u56e0\u6b64\uff0c\u5982\u679c\u6570\u7ec4\u957f\u5ea6\u4e3a 0\uff0c\u5219\u6570\u7ec4\u4e3a\u7a7a\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] array = {};\nif (array.length == 0) {\n    System.out.println(\"\u6570\u7ec4\u4e3a\u7a7a\");\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u5f0f 2\uff1a\u4f7f\u7528 isEmpty() \u65b9\u6cd5<\/strong><\/p>\n<p>\u5982\u679c\u4f7f\u7528 Guava \u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 isEmpty() \u65b9\u6cd5\u6765\u5224\u65ad\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\u3002<\/p>\n<pre>import com.google.common.base.EmptyArrays;\n\nint[] array = {};\nif (EmptyArrays.isEmpty(array)) {\n    System.out.println(\"\u6570\u7ec4\u4e3a\u7a7a\");\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5224\u65ad\u4e00\u4e2a\u7a7a\u6570\u7ec4\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>\u5224\u65ad java \u4e2d\u7a7a\u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u6bd4\u8f83\u957f\u5ea6\uff1a\u5982\u679c\u6570\u7ec4\u957f\u5ea6\u4e3a 0\uff0c\u5219\u6570\u7ec4\u4e3a\u7a7a\u3002\u4f7f\u7528 guava \u5e93\u7684 isempty() \u65b9\u6cd5\uff1a\u5982\u679c\u6570\u7ec4\u4e3a\u7a7a\uff0c\u5219\u8fd4\u56de true\u3002 \u5224\u65ad Java \u4e2d\u7a7a\u6570\u7ec4\u7684\u65b9\u6cd5 \u5728 Java \u4e2d\uff0c\u5224\u65ad\u4e00\u4e2a\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\u975e\u5e38\u7b80\u5355\u3002 \u65b9\u5f0f 1\uff1a\u6bd4\u8f83\u957f\u5ea6 \u6570\u7ec4\u7684 length \u5c5e\u6027\u8868\u793a\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u6570\u91cf\u3002\u56e0\u6b64\uff0c\u5982\u679c\u6570\u7ec4\u957f\u5ea6\u4e3a 0\uff0c\u5219\u6570\u7ec4\u4e3a\u7a7a\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] array = {}; if (array.length == 0) { System.out.println(&#8220;\u6570\u7ec4\u4e3a\u7a7a&#8221;); } \u767b\u5f55\u540e\u590d\u5236 \u65b9\u5f0f 2\uff1a\u4f7f\u7528 isEmpty() \u65b9\u6cd5 \u5982\u679c\u4f7f\u7528 Guava \u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528 isEmpty() \u65b9\u6cd5\u6765\u5224\u65ad\u6570\u7ec4\u662f\u5426\u4e3a\u7a7a\u3002 import com.google.common.base.EmptyArrays; int[] array = {}; if (EmptyArrays.isEmpty(array)) { System.out.println(&#8220;\u6570\u7ec4\u4e3a\u7a7a&#8221;); } \u767b\u5f55\u540e\u590d\u5236 [&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-66523","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66523","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=66523"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66523\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}