{"id":38827,"date":"2024-11-26T17:19:24","date_gmt":"2024-11-26T09:19:24","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38827\/"},"modified":"2024-11-26T17:19:24","modified_gmt":"2024-11-26T09:19:24","slug":"java%e6%80%8e%e4%b9%88%e5%8f%98%e9%87%8f%e7%9a%84%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38827\/","title":{"rendered":"java\u600e\u4e48\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u5b9a\u4e49\u5b57\u7b26\u4e32\u6570\u7ec4\u5305\u542b\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u58f0\u660e\u6570\u7ec4\u540d\u79f0\u5e76\u6307\u5b9a\u5143\u7d20\u7c7b\u578b\u4e3a string\u3002\u4f7f\u7528\u65b9\u62ec\u53f7 [] \u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u5728\u5927\u62ec\u53f7 {} \u4e2d\u6307\u5b9a\u6570\u7ec4\u7684\u5143\u7d20\u503c\uff0c\u7528\u9017\u53f7\u5206\u9694\u3002\u4f7f\u7528\u4e0b\u6807\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111507040040135.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u53d8\u91cf\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u5b9a\u4e49<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u503c\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>String[] arrayName = { \"element1\", \"element2\", ..., \"elementN\" };<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002<\/li>\n<li>[] \u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4\u3002<\/li>\n<li>String \u8868\u793a\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u662f\u5b57\u7b26\u4e32\u3002<\/li>\n<li>element1, element2, &#8230;, elementN \u662f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String[] names = { \"John\", \"Mary\", \"Bob\", \"Alice\" };<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u521b\u5efa\u5b57\u7b26\u4e32\u6570\u7ec4\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u6807\u8bbf\u95ee\u5176\u4e2d\u7684\u5143\u7d20\u3002\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre>System.out.println(names[0]); \/\/ \u8f93\u51fa \"John\"\nSystem.out.println(names[3]); \/\/ \u8f93\u51fa \"Alice\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\uff1a<\/p>\n<pre>for (String name : names) {\n  System.out.println(name);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u4e3a\uff1a<\/p>\n<pre>John\nMary\nBob\nAlice<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u53d8\u91cf\u7684\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\u5b57\u7b26\u4e32\u6570\u7ec4\u5305\u542b\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u58f0\u660e\u6570\u7ec4\u540d\u79f0\u5e76\u6307\u5b9a\u5143\u7d20\u7c7b\u578b\u4e3a string\u3002\u4f7f\u7528\u65b9\u62ec\u53f7 [] \u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4\u3002\u5728\u5927\u62ec\u53f7 {} \u4e2d\u6307\u5b9a\u6570\u7ec4\u7684\u5143\u7d20\u503c\uff0c\u7528\u9017\u53f7\u5206\u9694\u3002\u4f7f\u7528\u4e0b\u6807\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff0c\u4e0b\u6807\u4ece 0 \u5f00\u59cb\u3002 \u5982\u4f55\u5728 Java \u4e2d\u5b9a\u4e49 \u5728 Java \u4e2d\uff0c\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u7528\u6765\u5b58\u50a8\u4e00\u7cfb\u5217\u5b57\u7b26\u4e32\u503c\u3002\u8981\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a String[] arrayName = { &#8220;element1&#8221;, &#8220;element2&#8221;, &#8230;, &#8220;elementN&#8221; }; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a arrayName \u662f\u6570\u7ec4\u7684\u540d\u79f0\u3002 [] \u8868\u793a\u8fd9\u662f\u4e00\u4e2a\u6570\u7ec4\u3002 String \u8868\u793a\u6570\u7ec4\u7684\u5143\u7d20\u7c7b\u578b\u662f\u5b57\u7b26\u4e32\u3002 element1, element2, &#8230;, elementN \u662f\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u503c\u3002 \u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String[] names = { &#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;, &#8220;Alice&#8221; }; \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u5b57\u7b26\u4e32\u6570\u7ec4\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0b\u6807\u8bbf\u95ee\u5176\u4e2d\u7684\u5143\u7d20\u3002\u4e0b\u6807\u4ece 0 \u5f00\u59cb\uff0c\u6bd4\u5982\uff1a System.out.println(names[0]); \/\/ [&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-38827","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38827","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=38827"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38827\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}