{"id":64147,"date":"2025-05-03T11:25:28","date_gmt":"2025-05-03T03:25:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64147\/"},"modified":"2025-05-03T11:25:28","modified_gmt":"2025-05-03T03:25:28","slug":"java%e6%80%8e%e4%b9%88%e5%be%aa%e7%8e%af%e9%81%8d%e5%8e%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64147\/","title":{"rendered":"java\u600e\u4e48\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\uff1a1. \u4f7f\u7528\u589e\u5f3a\u578b for \u5faa\u73af\uff0c\u4f8b\u5982\uff1afor (string element : array) { &#8230; }\uff1b2. \u4f7f\u7528\u4f20\u7edf for \u5faa\u73af\uff0c\u4f8b\u5982\uff1afor (int i = 0; i <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110215275555854.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5faa\u73af\u904d\u5386 Java <\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u589e\u5f3a\u578b for \u5faa\u73af<\/strong><\/p>\n<p>\u589e\u5f3a\u578b for \u5faa\u73af\u662f\u4e00\u79cd\u7b80\u6d01\u6613\u7528\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>for (String element : array) {\n  \/\/ \u5bf9\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u64cd\u4f5c\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u4ee3\u7801\u4f7f\u7528\u589e\u5f3a\u578b for \u5faa\u73af\u904d\u5386\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\uff1a<\/p>\n<pre>String[] names = { \"Alice\", \"Bob\", \"Charlie\" };\n\nfor (String name : names) {\n  System.out.println(name);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre>Alice\nBob\nCharlie<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528\u4f20\u7edf for \u5faa\u73af<\/strong><\/p>\n<p>\u4f20\u7edf for \u5faa\u73af\u662f\u4e00\u79cd\u66f4\u901a\u7528\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>for (int i = 0; i &lt; array.length; i++) {\n  \/\/ \u5bf9\u6570\u7ec4\u7684\u7b2c i \u4e2a\u5143\u7d20\u8fdb\u884c\u64cd\u4f5c\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u4e0b\u9762\u4ee3\u7801\u4f7f\u7528\u4f20\u7edf for \u5faa\u73af\u904d\u5386\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\u7684\u957f\u5ea6\uff1a<\/p>\n<pre>String[] names = { \"Alice\", \"Bob\", \"Charlie\" };\n\nfor (int i = 0; i &lt; names.length; i++) {\n  System.out.println(names[i].length());\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre>5\n3\n7<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236\n<\/p><\/blockquote>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5faa\u73af\u904d\u5386\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\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4\u53ef\u4ee5\u4f7f\u7528\u4e24\u79cd\u65b9\u6cd5\uff1a1. \u4f7f\u7528\u589e\u5f3a\u578b for \u5faa\u73af\uff0c\u4f8b\u5982\uff1afor (string element : array) { &#8230; }\uff1b2. \u4f7f\u7528\u4f20\u7edf for \u5faa\u73af\uff0c\u4f8b\u5982\uff1afor (int i = 0; i \u5982\u4f55\u5faa\u73af\u904d\u5386 Java \u5728 Java \u4e2d\uff0c\u5faa\u73af\u904d\u5386\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u5e38\u89c1\u65b9\u6cd5\uff1a 1. \u4f7f\u7528\u589e\u5f3a\u578b for \u5faa\u73af \u589e\u5f3a\u578b for \u5faa\u73af\u662f\u4e00\u79cd\u7b80\u6d01\u6613\u7528\u7684\u904d\u5386\u65b9\u5f0f\uff0c\u8bed\u6cd5\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b for (String element : array) { \/\/ \u5bf9\u6bcf\u4e2a\u5143\u7d20\u8fdb\u884c\u64cd\u4f5c } \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u4e0b\u9762\u4ee3\u7801\u4f7f\u7528\u589e\u5f3a\u578b for \u5faa\u73af\u904d\u5386\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\uff1a String[] names = { &#8220;Alice&#8221;, &#8220;Bob&#8221;, &#8220;Charlie&#8221; }; [&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-64147","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64147","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=64147"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64147\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}