{"id":38761,"date":"2024-11-26T15:19:58","date_gmt":"2024-11-26T07:19:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38761\/"},"modified":"2024-11-26T15:19:58","modified_gmt":"2024-11-26T07:19:58","slug":"java%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89%e4%b8%80%e4%b8%aa%e7%a9%ba%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38761\/","title":{"rendered":"java\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u5b9a\u4e49\u7a7a\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf int[] myarray = {};\u4f7f\u7528 new \u5173\u952e\u5b57 int[] myarray = new int[0];\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111506062727420.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<h2>\u5982\u4f55\u5728 Java \u4e2d\u5b9a\u4e49\u7a7a\u6570\u7ec4<\/h2>\n<p>\u5728 Java \u4e2d\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u6570\u7ec4\u6709\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf<\/strong><\/p>\n<pre>int[] emptyArray1 = {};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57<\/strong><\/p>\n<pre>int[] emptyArray2 = new int[0];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u7a7a\u6570\u7ec4\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<h3>\u5177\u4f53\u793a\u4f8b<\/h3>\n<p>\u5047\u8bbe\u6211\u4eec\u60f3\u521b\u5efa\u4e00\u4e2a\u7a7a\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf<\/strong><\/p>\n<pre>String[] emptyStringArray = {};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57<\/strong><\/p>\n<pre>String[] emptyStringArray = new String[0];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u4f1a\u521b\u5efa\u957f\u5ea6\u4e3a 0 \u7684\u7a7a\u5b57\u7b26\u4e32\u6570\u7ec4\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 Array.length \u5c5e\u6027\u6765\u68c0\u67e5\u6570\u7ec4\u957f\u5ea6\uff1a<\/p>\n<pre>System.out.println(emptyStringArray.length); \/\/ \u8f93\u51fa\uff1a0<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3><\/h3>\n<p>\u4e24\u79cd\u65b9\u6cd5\u5728\u672c\u8d28\u4e0a\u662f\u6ca1\u6709\u533a\u522b\u7684\uff0c\u5b83\u4eec\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u7a7a\u6570\u7ec4\u3002\u4f46\u662f\uff0c\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf\u66f4\u52a0\u7b80\u6d01\uff0c\u66f4\u6613\u4e8e\u7406\u89e3\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u6570\u7ec4\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\u5b9a\u4e49\u7a7a\u6570\u7ec4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf int[] myarray = {};\u4f7f\u7528 new \u5173\u952e\u5b57 int[] myarray = new int[0]; \u5982\u4f55\u5728 Java \u4e2d\u5b9a\u4e49\u7a7a\u6570\u7ec4 \u5728 Java \u4e2d\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u6570\u7ec4\u6709\u4e24\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf int[] emptyArray1 = {}; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57 int[] emptyArray2 = new int[0]; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u957f\u5ea6\u4e3a 0 \u7684\u7a7a\u6570\u7ec4\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5177\u4f53\u793a\u4f8b \u5047\u8bbe\u6211\u4eec\u60f3\u521b\u5efa\u4e00\u4e2a\u7a7a\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528\u6570\u7ec4\u5b57\u9762\u91cf String[] emptyStringArray = {}; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 new \u5173\u952e\u5b57 String[] [&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-38761","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38761","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=38761"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38761\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}