{"id":34762,"date":"2024-11-26T14:47:19","date_gmt":"2024-11-26T06:47:19","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34762\/"},"modified":"2024-11-26T14:47:19","modified_gmt":"2024-11-26T06:47:19","slug":"java%e4%b8%ad%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e8%b5%8b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34762\/","title":{"rendered":"java\u4e2d\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u8d4b\u503c\u6216\u6570\u7ec4\u521d\u59cb\u5316\u5668\u8d4b\u503c\uff0c\u5143\u7d20\u7c7b\u578b\u5fc5\u987b\u4e00\u81f4\uff0c\u6570\u7ec4\u957f\u5ea6\u5728\u521b\u5efa\u65f6\u6307\u5b9a\uff0c\u53ef\u901a\u8fc7 length \u5c5e\u6027\u83b7\u53d6\u957f\u5ea6\uff0c\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u8bbf\u95ee\u5143\u7d20\uff0c\u6216\u901a\u8fc7 for-each \u5faa\u73af\u904d\u5386\u6240\u6709\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110302303254054.jpg\" class=\"aligncenter\" title=\"java\u4e2d\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" alt=\"java\u4e2d\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u8d4b\u503c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u8d4b\u503c\uff1a<\/p>\n<p><strong>1. \u76f4\u63a5\u8d4b\u503c<\/strong><\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u76f4\u63a5\u5c06\u5143\u7d20\u503c\u5206\u914d\u7ed9\u6570\u7ec4\u5143\u7d20\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String[] names = {\"John\", \"Mary\", \"Bob\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668<\/strong><\/p>\n<p>\u6570\u7ec4\u521d\u59cb\u5316\u5668\u662f\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>String[] names = new String[] {\"John\", \"Mary\", \"Bob\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u5fc5\u987b\u4e0e\u6570\u7ec4\u58f0\u660e\u4e2d\u7684\u7c7b\u578b\u4e00\u81f4\u3002<\/li>\n<li>\u6570\u7ec4\u7684\u957f\u5ea6\u5728\u521b\u5efa\u65f6\u5fc5\u987b\u6307\u5b9a\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7684 length \u5c5e\u6027\u6765\u83b7\u53d6\u6570\u7ec4\u7684\u957f\u5ea6\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u6765\u8bbf\u95ee\u7279\u5b9a\u5143\u7d20\uff0c\u4ece 0 \u5f00\u59cb\u7d22\u5f15\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 for-each \u5faa\u73af\u6765\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre>String[] names = {\"John\", \"Mary\", \"Bob\"};\n\nfor (String name : names) {\n    System.out.println(name);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u4e2d\u600e\u4e48\u8d4b\u503c\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>java \u4e2d\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u8d4b\u503c\u6216\u6570\u7ec4\u521d\u59cb\u5316\u5668\u8d4b\u503c\uff0c\u5143\u7d20\u7c7b\u578b\u5fc5\u987b\u4e00\u81f4\uff0c\u6570\u7ec4\u957f\u5ea6\u5728\u521b\u5efa\u65f6\u6307\u5b9a\uff0c\u53ef\u901a\u8fc7 length \u5c5e\u6027\u83b7\u53d6\u957f\u5ea6\uff0c\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u8bbf\u95ee\u5143\u7d20\uff0c\u6216\u901a\u8fc7 for-each \u5faa\u73af\u904d\u5386\u6240\u6709\u5143\u7d20\u3002 Java \u4e2d\u8d4b\u503c \u5728 Java \u4e2d\uff0c\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u8d4b\u503c\uff1a 1. \u76f4\u63a5\u8d4b\u503c \u8fd9\u79cd\u65b9\u5f0f\u76f4\u63a5\u5c06\u5143\u7d20\u503c\u5206\u914d\u7ed9\u6570\u7ec4\u5143\u7d20\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String[] names = {&#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;}; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528\u6570\u7ec4\u521d\u59cb\u5316\u5668 \u6570\u7ec4\u521d\u59cb\u5316\u5668\u662f\u4e00\u79cd\u66f4\u7b80\u6d01\u7684\u65b9\u5f0f\u6765\u521d\u59cb\u5316\u6570\u7ec4\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a String[] names = new String[] {&#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;}; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4ed6\u6ce8\u610f\u4e8b\u9879 \u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u578b\u5fc5\u987b\u4e0e\u6570\u7ec4\u58f0\u660e\u4e2d\u7684\u7c7b\u578b\u4e00\u81f4\u3002 \u6570\u7ec4\u7684\u957f\u5ea6\u5728\u521b\u5efa\u65f6\u5fc5\u987b\u6307\u5b9a\u3002 \u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7684 length \u5c5e\u6027\u6765\u83b7\u53d6\u6570\u7ec4\u7684\u957f\u5ea6\u3002 \u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u6765\u8bbf\u95ee\u7279\u5b9a\u5143\u7d20\uff0c\u4ece 0 \u5f00\u59cb\u7d22\u5f15\u3002 \u53ef\u4ee5\u4f7f\u7528 for-each \u5faa\u73af\u6765\u904d\u5386\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u3002 \u4f8b\u5982\uff1a String[] names = {&#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;}; for (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-34762","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34762","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=34762"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34762\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}