{"id":65405,"date":"2025-05-03T12:30:20","date_gmt":"2025-05-03T04:30:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65405\/"},"modified":"2025-05-03T12:30:20","modified_gmt":"2025-05-03T04:30:20","slug":"%e5%a4%a7%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%ae%9a%e4%b9%89java-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65405\/","title":{"rendered":"\u5927\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49java"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u6709\u4e24\u79cd\u65b9\u6cd5\u6765\u5b9a\u4e49\u5927\u6570\u7ec4\uff1a1. \u4f7f\u7528\u6807\u51c6\u6570\u7ec4\u8bed\u6cd5\uff0c\u5982 int[] myarray = new int[1000000]\uff1b2. \u4f7f\u7528 guava \u5e93\u7684 intarrays \u5b9e\u7528\u7a0b\u5e8f\u7c7b\uff0c\u5982 ints.toarray(1, 2, 3, 4, 5)\u3002\u4f7f\u7528\u5927\u6570\u7ec4\u9700\u8981\u6ce8\u610f\u5185\u5b58\u6d88\u8017\u3001\u6027\u80fd\u548c\u5783\u573e\u56de\u6536\u7b49\u95ee\u9898\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u53ea\u521b\u5efa\u9700\u8981\u7684\u6570\u7ec4\u5927\u5c0f\u3001\u4f7f\u7528\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\u3001\u8003\u8651\u6570\u7ec4\u7f13\u51b2\u6c60\u548c\u4f7f\u7528\u5e93\u6765\u7b80\u5316\u64cd\u4f5c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111223484652791.jpg\" class=\"aligncenter\" title=\"\u5927\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49java\u63d2\u56fe\" alt=\"\u5927\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49java\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5b9a\u4e49 Java \u4e2d\u7684\u5927\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\u5b9a\u4e49\u5927\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528\u6807\u51c6\u6570\u7ec4<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u6807\u51c6\u6570\u7ec4\u8bed\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>int[] myArray = new int[1000000];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b 100 \u4e07\u4e2a int \u5143\u7d20\u7684\u6570\u7ec4\u3002<\/p>\n<p><strong>2. \u4f7f\u7528 Guava \u5e93<\/strong><\/p>\n<p>Guava \u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u79f0\u4e3a IntArrays \u7684\u5b9e\u7528\u7a0b\u5e8f\u7c7b\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u65b9\u4fbf\u7684\u65b9\u6cd5\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u5927\u6570\u7ec4\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>import com.google.common.primitives.Ints;\n\nint[] myArray = Ints.toArray(1, 2, 3, 4, 5);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b 5 \u4e2a int \u5143\u7d20\u7684\u6570\u7ec4\u3002<\/p>\n<p><strong>\u4f7f\u7528\u5927\u6570\u7ec4\u7684\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<p>\u4f7f\u7528\u5927\u6570\u7ec4\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li> <strong>\u5185\u5b58\u6d88\u8017\uff1a<\/strong>\u5927\u6570\u7ec4\u4f1a\u6d88\u8017\u5927\u91cf\u5185\u5b58\uff0c\u56e0\u6b64\u5728\u521b\u5efa\u4e4b\u524d\u52a1\u5fc5\u8003\u8651\u53ef\u7528\u5185\u5b58\u3002<\/li>\n<li> <strong>\u6027\u80fd\uff1a<\/strong>\u8bbf\u95ee\u5927\u6570\u7ec4\u5143\u7d20\u53ef\u80fd\u6bd4\u8bbf\u95ee\u5c0f\u6570\u7ec4\u5143\u7d20\u6162\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u968f\u673a\u8bbf\u95ee\u3002<\/li>\n<li> <strong>\u5783\u573e\u56de\u6536\uff1a<\/strong>\u5927\u6570\u7ec4\u7684\u5783\u573e\u56de\u6536\u53ef\u80fd\u5f88\u8017\u65f6\uff0c\u56e0\u6b64\u5728\u4e0d\u518d\u9700\u8981\u5b83\u4eec\u65f6\u53ca\u65f6\u91ca\u653e\u5b83\u4eec\u3002<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<p>\u4e3a\u4e86\u6709\u6548\u4f7f\u7528\u5927\u6570\u7ec4\uff0c\u5efa\u8bae\u9075\u5faa\u4ee5\u4e0b\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<ul>\n<li>\u53ea\u521b\u5efa\u771f\u6b63\u9700\u8981\u7684\u6570\u7ec4\u5927\u5c0f\u3002<\/li>\n<li>\u5982\u679c\u53ef\u80fd\uff0c\u4f7f\u7528\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\uff08\u4f8b\u5982 int[] \u800c\u4e0d\u662f Integer[]\uff09\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528\u6570\u7ec4\u7f13\u51b2\u6c60\u6765\u91cd\u7528\u6570\u7ec4\u3002<\/li>\n<li>\u4f7f\u7528 Guava \u7b49\u5e93\u6765\u7b80\u5316\u5927\u6570\u7ec4\u7684\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5927\u6570\u7ec4\u600e\u4e48\u5b9a\u4e49java\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>java \u4e2d\u6709\u4e24\u79cd\u65b9\u6cd5\u6765\u5b9a\u4e49\u5927\u6570\u7ec4\uff1a1. \u4f7f\u7528\u6807\u51c6\u6570\u7ec4\u8bed\u6cd5\uff0c\u5982 int[] myarray = new int[1000000]\uff1b2. \u4f7f\u7528 guava \u5e93\u7684 intarrays \u5b9e\u7528\u7a0b\u5e8f\u7c7b\uff0c\u5982 ints.toarray(1, 2, 3, 4, 5)\u3002\u4f7f\u7528\u5927\u6570\u7ec4\u9700\u8981\u6ce8\u610f\u5185\u5b58\u6d88\u8017\u3001\u6027\u80fd\u548c\u5783\u573e\u56de\u6536\u7b49\u95ee\u9898\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u53ea\u521b\u5efa\u9700\u8981\u7684\u6570\u7ec4\u5927\u5c0f\u3001\u4f7f\u7528\u539f\u59cb\u7c7b\u578b\u6570\u7ec4\u3001\u8003\u8651\u6570\u7ec4\u7f13\u51b2\u6c60\u548c\u4f7f\u7528\u5e93\u6765\u7b80\u5316\u64cd\u4f5c\u3002 \u5982\u4f55\u5b9a\u4e49 Java \u4e2d\u7684\u5927\u6570\u7ec4 \u5728 Java \u4e2d\u5b9a\u4e49\u5927\u6570\u7ec4\u6709\u4e24\u79cd\u4e3b\u8981\u65b9\u6cd5\uff1a 1. \u4f7f\u7528\u6807\u51c6\u6570\u7ec4 \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528\u6807\u51c6\u6570\u7ec4\u8bed\u6cd5\uff0c\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b int[] myArray = new int[1000000]; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u5305\u542b 100 \u4e07\u4e2a int \u5143\u7d20\u7684\u6570\u7ec4\u3002 2. \u4f7f\u7528 Guava \u5e93 Guava \u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u79f0\u4e3a IntArrays \u7684\u5b9e\u7528\u7a0b\u5e8f\u7c7b\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u65b9\u4fbf\u7684\u65b9\u6cd5\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u5927\u6570\u7ec4\u3002\u4f8b\u5982\uff1a import com.google.common.primitives.Ints; int[] myArray = Ints.toArray(1, 2, 3, [&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-65405","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65405","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=65405"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65405\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}