{"id":66974,"date":"2025-05-03T11:57:36","date_gmt":"2025-05-03T03:57:36","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66974\/"},"modified":"2025-05-03T11:57:36","modified_gmt":"2025-05-03T03:57:36","slug":"java%e9%87%8c%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e5%88%9d%e5%a7%8b%e5%8c%96-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66974\/","title":{"rendered":"java\u91cc\u600e\u4e48\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u521d\u59cb\u5316"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\uff0c\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u9700\u8981\u6307\u5b9a\u5927\u5c0f\u548c\u5206\u914d\u7a7a\u95f4\uff1a\u58f0\u660e\u6570\u7ec4\u5927\u5c0f\uff1astring[] array = new string[size];\u5206\u522b\u521d\u59cb\u5316\u6bcf\u4e2a\u5143\u7d20\uff1astring[] array = {ele1, ele2, &#8230;};\u904d\u5386\u6240\u6709\u5143\u7d20\uff1afor (string e : array) { &#8230; };\u6ce8\u610f\uff0c\u6570\u7ec4\u5927\u5c0f\u4e0d\u53ef\u66f4\u6539\uff0c\u672a\u521d\u59cb\u5316\u5143\u7d20\u4e3a null\uff0c\u8d8a\u754c\u8bbf\u95ee\u4f1a\u5f15\u53d1\u5f02\u5e38\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/17\/2024111721304533585.jpg\" class=\"aligncenter\" title=\"java\u91cc\u600e\u4e48\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u521d\u59cb\u5316\u63d2\u56fe\" alt=\"java\u91cc\u600e\u4e48\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u521d\u59cb\u5316\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u4e2d\u5b9a\u4e49\u548c\u521d\u59cb\u5316<\/strong><\/p>\n<p>\u5728Java\u4e2d\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u65f6\uff0c\u9996\u5148\u9700\u8981\u58f0\u660e\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u7136\u540e\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u3002\u53ef\u4ee5\u5206\u522b\u4f7f\u7528new\u5173\u952e\u5b57\u548c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5b9a\u4e49\u6570\u7ec4\u5927\u5c0f\uff1a<\/strong><\/p>\n<pre>String[] names = new String[5];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb35\u4e2a\u5b57\u7b26\u4e32\u5143\u7d20\u7684\u6570\u7ec4\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e3a\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u5206\u914d\u503c\u3002<\/p>\n<pre>String[] names = new String[] {\"Alice\", \"Bob\", \"Carol\", \"Dave\", \"Eve\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7684\u65b0\u5efa\u548c\u521d\u59cb\u5316\u8bed\u6cd5\uff1a<\/p>\n<pre>String[] names = {\"Alice\", \"Bob\", \"Carol\", \"Dave\", \"Eve\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u6f14\u793a\u4e86\u5982\u4f55\u5b9a\u4e49\u3001\u521d\u59cb\u5316\u548c\u8bbf\u95ee\u5b57\u7b26\u4e32\u6570\u7ec4\uff1a<\/p>\n<pre>String[] names = {\"Alice\", \"Bob\", \"Carol\"};\n\n\/\/ \u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\nSystem.out.println(names[0]); \/\/ \u8f93\u51fa \"Alice\"\n\n\/\/ \u4fee\u6539\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\nnames[1] = \"Bob Smith\";\n\n\/\/ \u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\nfor (String name : names) {\n    System.out.println(name);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u4e00\u65e6\u521b\u5efa\u540e\uff0c\u5176\u5927\u5c0f\u5c31\u4e0d\u80fd\u6539\u53d8\u3002<\/li>\n<li>\u5982\u679c\u6570\u7ec4\u672a\u521d\u59cb\u5316\uff0c\u5219\u5176\u5143\u7d20\u5c06\u5305\u542bnull\u503c\u3002<\/li>\n<li>\u8bbf\u95ee\u8d85\u51fa\u6570\u7ec4\u8303\u56f4\u7684\u5143\u7d20\u5c06\u5bfc\u81f4ArrayIndexOutOfBoundsException\u5f02\u5e38\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u91cc\u600e\u4e48\u5b9a\u4e49\u521d\u59cb\u5316\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>\u5728 java \u4e2d\uff0c\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u9700\u8981\u6307\u5b9a\u5927\u5c0f\u548c\u5206\u914d\u7a7a\u95f4\uff1a\u58f0\u660e\u6570\u7ec4\u5927\u5c0f\uff1astring[] array = new string[size];\u5206\u522b\u521d\u59cb\u5316\u6bcf\u4e2a\u5143\u7d20\uff1astring[] array = {ele1, ele2, &#8230;};\u904d\u5386\u6240\u6709\u5143\u7d20\uff1afor (string e : array) { &#8230; };\u6ce8\u610f\uff0c\u6570\u7ec4\u5927\u5c0f\u4e0d\u53ef\u66f4\u6539\uff0c\u672a\u521d\u59cb\u5316\u5143\u7d20\u4e3a null\uff0c\u8d8a\u754c\u8bbf\u95ee\u4f1a\u5f15\u53d1\u5f02\u5e38\u3002 Java\u4e2d\u5b9a\u4e49\u548c\u521d\u59cb\u5316 \u5728Java\u4e2d\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u65f6\uff0c\u9996\u5148\u9700\u8981\u58f0\u660e\u6570\u7ec4\u7684\u5927\u5c0f\uff0c\u7136\u540e\u5206\u914d\u5185\u5b58\u7a7a\u95f4\u3002\u53ef\u4ee5\u5206\u522b\u4f7f\u7528new\u5173\u952e\u5b57\u548c\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u6765\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002 \u5b9a\u4e49\u6570\u7ec4\u5927\u5c0f\uff1a String[] names = new String[5]; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb35\u4e2a\u5b57\u7b26\u4e32\u5143\u7d20\u7684\u6570\u7ec4\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\uff1a \u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\u4e3a\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u5206\u914d\u503c\u3002 String[] names = new String[] {&#8220;Alice&#8221;, &#8220;Bob&#8221;, &#8220;Carol&#8221;, &#8220;Dave&#8221;, &#8220;Eve&#8221;}; \u767b\u5f55\u540e\u590d\u5236 \u4e5f\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7684\u65b0\u5efa\u548c\u521d\u59cb\u5316\u8bed\u6cd5\uff1a String[] names = {&#8220;Alice&#8221;, &#8220;Bob&#8221;, &#8220;Carol&#8221;, &#8220;Dave&#8221;, &#8220;Eve&#8221;}; \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a [&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-66974","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66974","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=66974"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66974\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66974"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66974"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66974"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}