{"id":36557,"date":"2024-11-26T16:54:34","date_gmt":"2024-11-26T08:54:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36557\/"},"modified":"2024-11-26T16:54:34","modified_gmt":"2024-11-26T08:54:34","slug":"%e5%af%b9%e8%b1%a1%e6%95%b0%e7%bb%84%e6%9c%89%e5%93%aa%e4%ba%9b-java","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36557\/","title":{"rendered":"\u5bf9\u8c61\u6570\u7ec4\u6709\u54ea\u4e9b java"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u7684\u5bf9\u8c61\u6570\u7ec4\u5141\u8bb8\u6709\u5e8f\u5730\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528\uff0c\u5305\u62ec\u5f15\u7528\u7c7b\u578b\u548c\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\u4e24\u79cd\u7c7b\u578b\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u5b58\u50a8\u5bf9\u8c61\u96c6\u5408\u3001\u7c7b\u578b\u5b89\u5168\u548c\u52a8\u6001\u5927\u5c0f\u66f4\u6539\u7684\u4f18\u70b9\uff0c\u4f46\u4e5f\u5b58\u5728\u5185\u5b58\u5f00\u9500\u548c\u62c6\u7bb1\/\u88c5\u7bb1\u64cd\u4f5c\u7684\u7f3a\u70b9\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111210100483274.jpg\" class=\"aligncenter\" title=\"\u5bf9\u8c61\u6570\u7ec4\u6709\u54ea\u4e9b java\u63d2\u56fe\" alt=\"\u5bf9\u8c61\u6570\u7ec4\u6709\u54ea\u4e9b java\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u7684\u5bf9\u8c61\u6570\u7ec4<\/strong><\/p>\n<p>\u5bf9\u8c61\u6570\u7ec4\u662f Java \u4e2d\u7684\u7279\u6b8a\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u5141\u8bb8\u4ee5\u6709\u5e8f\u7684\u65b9\u5f0f\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528\u3002<\/p>\n<p><strong>\u7c7b\u578b<\/strong><\/p>\n<p>Java \u4e2d\u652f\u6301\u4e24\u79cd\u7c7b\u578b\u5bf9\u8c61\u6570\u7ec4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\uff1a<\/strong>\u5b58\u50a8\u5bf9\u5176\u4ed6\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u4f8b\u5982\uff1aObject[] \u6216 String[]\u3002<\/li>\n<li> <strong>\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\uff1a<\/strong>\u5b58\u50a8\u539f\u59cb\u7c7b\u578b\u7684\u503c\uff0c\u5982 int\u3001double \u6216 boolean\u3002<\/li>\n<\/ul>\n<p><strong>\u521b\u5efa<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>Object[] objects = new Object[size];\nString[] strings = new String[size];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d size \u662f\u6570\u7ec4\u7684\u5927\u5c0f\u3002<\/p>\n<p><strong>\u8bbf\u95ee\u5143\u7d20<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u6765\u8bbf\u95ee\u5bf9\u8c61\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a<\/p>\n<pre>objects[index] = myObject;\nString myString = strings[index];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u957f\u5ea6<\/strong><\/p>\n<p>\u5bf9\u8c61\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7 length \u5c5e\u6027\u83b7\u53d6\uff1a<\/p>\n<pre>int length = objects.length;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<p>\u4f7f\u7528\u5bf9\u8c61\u6570\u7ec4\u7684\u4f18\u70b9\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>\u65b9\u4fbf\u5730\u5b58\u50a8\u5bf9\u8c61\u96c6\u5408\uff1a<\/strong>\u5bf9\u8c61\u6570\u7ec4\u63d0\u4f9b\u4e86\u4e00\u79cd\u4fbf\u6377\u7684\u65b9\u6cd5\u6765\u6309\u987a\u5e8f\u5b58\u50a8\u5bf9\u8c61\u3002<\/li>\n<li> <strong>\u7c7b\u578b\u5b89\u5168\uff1a<\/strong>\u5f15\u7528\u7c7b\u578b\u6570\u7ec4\u4fdd\u8bc1\u4e86\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u7684\u5bf9\u8c61\u4e0e\u58f0\u660e\u7684\u7c7b\u578b\u5339\u914d\u3002<\/li>\n<li> <strong>\u52a8\u6001\u5927\u5c0f\uff1a<\/strong>\u5bf9\u8c61\u6570\u7ec4\u7684\u5927\u5c0f\u53ef\u4ee5\u5728\u8fd0\u884c\u65f6\u66f4\u6539\uff0c\u4f7f\u5176\u66f4\u7075\u6d3b\u3002<\/li>\n<\/ul>\n<p><strong>\u7f3a\u70b9<\/strong><\/p>\n<p>\u4f7f\u7528\u5bf9\u8c61\u6570\u7ec4\u7684\u7f3a\u70b9\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>\u5185\u5b58\u5f00\u9500\uff1a<\/strong>\u5bf9\u8c61\u6570\u7ec4\u9700\u8981\u6bd4\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\u66f4\u591a\u7684\u5185\u5b58\uff0c\u56e0\u4e3a\u5b83\u4eec\u5b58\u50a8\u7684\u662f\u5bf9\u8c61\u5f15\u7528\u3002<\/li>\n<li> <strong>\u62c6\u7bb1\u548c\u88c5\u7bb1\uff1a<\/strong>\u5f53\u8bbf\u95ee\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u62c6\u7bb1\u548c\u88c5\u7bb1\u64cd\u4f5c\uff0c\u8fd9\u53ef\u80fd\u4f1a\u964d\u4f4e\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5bf9\u8c61\u6570\u7ec4\u6709\u54ea\u4e9b java\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\u7684\u5bf9\u8c61\u6570\u7ec4\u5141\u8bb8\u6709\u5e8f\u5730\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528\uff0c\u5305\u62ec\u5f15\u7528\u7c7b\u578b\u548c\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\u4e24\u79cd\u7c7b\u578b\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u5b58\u50a8\u5bf9\u8c61\u96c6\u5408\u3001\u7c7b\u578b\u5b89\u5168\u548c\u52a8\u6001\u5927\u5c0f\u66f4\u6539\u7684\u4f18\u70b9\uff0c\u4f46\u4e5f\u5b58\u5728\u5185\u5b58\u5f00\u9500\u548c\u62c6\u7bb1\/\u88c5\u7bb1\u64cd\u4f5c\u7684\u7f3a\u70b9\u3002 Java \u4e2d\u7684\u5bf9\u8c61\u6570\u7ec4 \u5bf9\u8c61\u6570\u7ec4\u662f Java \u4e2d\u7684\u7279\u6b8a\u6570\u636e\u7ed3\u6784\uff0c\u5b83\u5141\u8bb8\u4ee5\u6709\u5e8f\u7684\u65b9\u5f0f\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528\u3002 \u7c7b\u578b Java \u4e2d\u652f\u6301\u4e24\u79cd\u7c7b\u578b\u5bf9\u8c61\u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5f15\u7528\u7c7b\u578b\u6570\u7ec4\uff1a\u5b58\u50a8\u5bf9\u5176\u4ed6\u5bf9\u8c61\u7684\u5f15\u7528\u3002\u4f8b\u5982\uff1aObject[] \u6216 String[]\u3002 \u539f\u59cb\u7c7b\u578b\u6570\u7ec4\uff1a\u5b58\u50a8\u539f\u59cb\u7c7b\u578b\u7684\u503c\uff0c\u5982 int\u3001double \u6216 boolean\u3002 \u521b\u5efa \u8981\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a Object[] objects = new Object[size]; String[] strings = new String[size]; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d size \u662f\u6570\u7ec4\u7684\u5927\u5c0f\u3002 \u8bbf\u95ee\u5143\u7d20 \u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u7d22\u5f15\u6765\u8bbf\u95ee\u5bf9\u8c61\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\uff1a objects[index] = myObject; String myString = strings[index]; \u767b\u5f55\u540e\u590d\u5236 \u957f\u5ea6 \u5bf9\u8c61\u6570\u7ec4\u7684\u957f\u5ea6\u53ef\u4ee5\u901a\u8fc7 length \u5c5e\u6027\u83b7\u53d6\uff1a int length = objects.length; \u767b\u5f55\u540e\u590d\u5236 \u4f18\u70b9 \u4f7f\u7528\u5bf9\u8c61\u6570\u7ec4\u7684\u4f18\u70b9\u5305\u62ec\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-36557","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36557","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=36557"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36557\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}