{"id":39010,"date":"2024-11-26T10:43:06","date_gmt":"2024-11-26T02:43:06","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39010\/"},"modified":"2024-11-26T10:43:06","modified_gmt":"2024-11-26T02:43:06","slug":"%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%a3%b0%e6%98%8e%e5%9c%a8java","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39010\/","title":{"rendered":"\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u58f0\u660e\u5728java"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u58f0\u660e\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a\u9759\u6001\u521d\u59cb\u5316\uff0c\u4f7f\u7528\u82b1\u62ec\u53f7\u521d\u59cb\u5316\u6570\u7ec4\u5e76\u6307\u5b9a\u5143\u7d20\u3002\u52a8\u6001\u521d\u59cb\u5316\uff0c\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u65b0\u6570\u7ec4\u5e76\u624b\u52a8\u6307\u5b9a\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111521305521605.jpg\" class=\"aligncenter\" title=\"\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u58f0\u660e\u5728java\u63d2\u56fe\" alt=\"\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u58f0\u660e\u5728java\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u4e2d\u58f0\u660e<\/strong><\/p>\n<p>\u5728 Java \u4e2d\u58f0\u660e\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u9759\u6001\u521d\u59cb\u5316<\/strong><\/p>\n<pre>String[] myArray = { \"Hello\", \"World\", \"!\" };<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u7528\u82b1\u62ec\u53f7 ({}) \u6765\u521d\u59cb\u5316\u6570\u7ec4\u5e76\u6307\u5b9a\u5176\u5143\u7d20\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>2. \u52a8\u6001\u521d\u59cb\u5316<\/strong><\/p>\n<pre>String[] myArray = new String[3];\nmyArray[0] = \"Hello\";\nmyArray[1] = \"World\";\nmyArray[2] = \"!\";<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\u5e76\u624b\u52a8\u6307\u5b9a\u5176\u5143\u7d20\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u7ec4\u7684\u5927\u5c0f\u5728\u521b\u5efa\u65f6\u786e\u5b9a\uff0c\u5e76\u4e14\u5728\u4ee5\u540e\u4e0d\u80fd\u88ab\u66f4\u6539\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 null \u503c\u6765\u8868\u793a\u7a7a\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1amyArray[2] = null;<\/li>\n<li>\u6570\u7ec4\u5143\u7d20\u7684\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u3002\u56e0\u6b64\uff0cmyArray[0] \u662f\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0cmyArray[myArray.length &#8211; 1] \u662f\u6700\u540e\u4e00\u4e2a\u5143\u7d20\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>String[] daysOfWeek = { \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\" };\n\nfor (String day : daysOfWeek) {\n  System.out.println(day);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u58f0\u660e\u4e00\u4e2a\u5305\u542b\u4e00\u5468\u4e2d\u4e03\u5929\u7684\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u7136\u540e\u904d\u5386\u6570\u7ec4\u5e76\u6253\u5370\u6bcf\u4e2a\u5143\u7d20\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u58f0\u660e\u5728java\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\u58f0\u660e\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a\u9759\u6001\u521d\u59cb\u5316\uff0c\u4f7f\u7528\u82b1\u62ec\u53f7\u521d\u59cb\u5316\u6570\u7ec4\u5e76\u6307\u5b9a\u5143\u7d20\u3002\u52a8\u6001\u521d\u59cb\u5316\uff0c\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u65b0\u6570\u7ec4\u5e76\u624b\u52a8\u6307\u5b9a\u5143\u7d20\u3002 Java\u4e2d\u58f0\u660e \u5728 Java \u4e2d\u58f0\u660e\u5b57\u7b26\u4e32\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a 1. \u9759\u6001\u521d\u59cb\u5316 String[] myArray = { &#8220;Hello&#8221;, &#8220;World&#8221;, &#8220;!&#8221; }; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u79cd\u65b9\u6cd5\u4f7f\u7528\u82b1\u62ec\u53f7 ({}) \u6765\u521d\u59cb\u5316\u6570\u7ec4\u5e76\u6307\u5b9a\u5176\u5143\u7d20\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 2. \u52a8\u6001\u521d\u59cb\u5316 String[] myArray = new String[3]; myArray[0] = &#8220;Hello&#8221;; myArray[1] = &#8220;World&#8221;; myArray[2] = &#8220;!&#8221;; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u79cd\u65b9\u6cd5\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u7ec4\u5e76\u624b\u52a8\u6307\u5b9a\u5176\u5143\u7d20\u3002 \u6ce8\u610f\uff1a \u6570\u7ec4\u7684\u5927\u5c0f\u5728\u521b\u5efa\u65f6\u786e\u5b9a\uff0c\u5e76\u4e14\u5728\u4ee5\u540e\u4e0d\u80fd\u88ab\u66f4\u6539\u3002 \u53ef\u4ee5\u4f7f\u7528 null \u503c\u6765\u8868\u793a\u7a7a\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1amyArray[2] = null; \u6570\u7ec4\u5143\u7d20\u7684\u7d22\u5f15\u4ece 0 \u5f00\u59cb\u3002\u56e0\u6b64\uff0cmyArray[0] \u662f\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0cmyArray[myArray.length &#8211; [&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-39010","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39010","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=39010"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39010\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}