{"id":65235,"date":"2025-05-03T16:22:31","date_gmt":"2025-05-03T08:22:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65235\/"},"modified":"2025-05-03T16:22:31","modified_gmt":"2025-05-03T08:22:31","slug":"java%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%b0%81%e8%a3%85-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65235\/","title":{"rendered":"java\u6570\u7ec4\u600e\u4e48\u5c01\u88c5"},"content":{"rendered":"<blockquote><p>\n  java\u6570\u7ec4\u53ef\u901a\u8fc7\u5305\u88c5\u7c7b\u5c01\u88c5\u6210\u5bf9\u8c61\u6570\u7ec4\uff0c\u6269\u5c55\u5176\u529f\u80fd\uff0c\u4fbf\u4e8e\u4f20\u9012\u548c\u5904\u7406\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a1. \u4f7f\u7528\u6d41\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\uff1b2. \u4f7f\u7528maptoobj()\u5c06\u5143\u7d20\u6620\u5c04\u5230\u5305\u88c5\u7c7b\u5bf9\u8c61\uff1b3. \u4f7f\u7528toarray()\u5c06\u6d41\u8f6c\u6362\u4e3a\u5bf9\u8c61\u6570\u7ec4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111213454237673.jpg\" class=\"aligncenter\" title=\"java\u6570\u7ec4\u600e\u4e48\u5c01\u88c5\u63d2\u56fe\" alt=\"java\u6570\u7ec4\u600e\u4e48\u5c01\u88c5\u63d2\u56fe\" \/><\/p>\n<p><strong>Java\u6570\u7ec4\u5c01\u88c5<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a\u5982\u4f55\u5c01\u88c5Java\u6570\u7ec4\uff1f<\/strong><\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong>\u5229\u7528\u5305\u88c5\u7c7b\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u5c01\u88c5\u6210\u5bf9\u8c61\u6570\u7ec4\u3002<\/p>\n<p><strong>\u8be6\u89e3\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>Java\u6570\u7ec4\u662f\u5e95\u5c42\u7684\u539f\u751f\u6570\u636e\u7ed3\u6784\uff0c\u4e0d\u80fd\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528\u3002\u8981\u5c01\u88c5\u6570\u7ec4\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u5bf9\u8c61\u6570\u7ec4\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u5305\u88c5\u7c7b\uff1a<\/strong><\/p>\n<ul>\n<li>\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u5305\u88c5\u7c7b\u53ef\u4ee5\u5b58\u50a8\u5bf9\u5e94\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u503c\uff0c\u5e76\u63d0\u4f9b\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002<\/li>\n<li>\u4f8b\u5982\uff0cint[]\u6570\u7ec4\u53ef\u4ee5\u8f6c\u6362\u6210Integer[]\u5bf9\u8c61\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8f6c\u6362\u65b9\u6cd5\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528Arrays.stream()\u65b9\u6cd5\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\uff0c\u7136\u540e\u4f7f\u7528mapToObj()\u65b9\u6cd5\u5c06\u6bcf\u4e2a\u5143\u7d20\u6620\u5c04\u5230\u5305\u88c5\u7c7b\u5bf9\u8c61\u3002<\/li>\n<li>\u6700\u540e\uff0c\u4f7f\u7528toArray()\u65b9\u6cd5\u5c06\u6d41\u8f6c\u6362\u4e3a\u5bf9\u8c61\u6570\u7ec4\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>int[] intArray = {1, 2, 3};\nInteger[] intArrayWrapped = Arrays.stream(intArray)\n                                   .mapToObj(Integer::valueOf)\n                                   .toArray(Integer[]::new);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5c01\u88c5\u7684\u597d\u5904\uff1a<\/strong><\/p>\n<ul>\n<li>\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528<\/li>\n<li>\u6269\u5c55\u6570\u7ec4\u529f\u80fd\uff08\u4f8b\u5982\uff0c\u6392\u5e8f\u3001\u67e5\u627e\uff09<\/li>\n<li>\u65b9\u4fbf\u6570\u7ec4\u7684\u4f20\u9012\u548c\u5904\u7406<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u600e\u4e48\u5c01\u88c5\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\u6570\u7ec4\u53ef\u901a\u8fc7\u5305\u88c5\u7c7b\u5c01\u88c5\u6210\u5bf9\u8c61\u6570\u7ec4\uff0c\u6269\u5c55\u5176\u529f\u80fd\uff0c\u4fbf\u4e8e\u4f20\u9012\u548c\u5904\u7406\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a1. \u4f7f\u7528\u6d41\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\uff1b2. \u4f7f\u7528maptoobj()\u5c06\u5143\u7d20\u6620\u5c04\u5230\u5305\u88c5\u7c7b\u5bf9\u8c61\uff1b3. \u4f7f\u7528toarray()\u5c06\u6d41\u8f6c\u6362\u4e3a\u5bf9\u8c61\u6570\u7ec4\u3002 Java\u6570\u7ec4\u5c01\u88c5 \u95ee\u9898\uff1a\u5982\u4f55\u5c01\u88c5Java\u6570\u7ec4\uff1f \u7b54\u6848\uff1a\u5229\u7528\u5305\u88c5\u7c7b\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u5c01\u88c5\u6210\u5bf9\u8c61\u6570\u7ec4\u3002 \u8be6\u89e3\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Java\u6570\u7ec4\u662f\u5e95\u5c42\u7684\u539f\u751f\u6570\u636e\u7ed3\u6784\uff0c\u4e0d\u80fd\u5b58\u50a8\u5bf9\u8c61\u5f15\u7528\u3002\u8981\u5c01\u88c5\u6570\u7ec4\uff0c\u9700\u8981\u5c06\u5176\u8f6c\u6362\u4e3a\u5bf9\u8c61\u6570\u7ec4\uff0c\u65b9\u6cd5\u5982\u4e0b\uff1a \u4f7f\u7528\u5305\u88c5\u7c7b\uff1a \u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u5305\u88c5\u7c7b\u53ef\u4ee5\u5b58\u50a8\u5bf9\u5e94\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u503c\uff0c\u5e76\u63d0\u4f9b\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002 \u4f8b\u5982\uff0cint[]\u6570\u7ec4\u53ef\u4ee5\u8f6c\u6362\u6210Integer[]\u5bf9\u8c61\u6570\u7ec4\u3002 \u8f6c\u6362\u65b9\u6cd5\uff1a \u4f7f\u7528Arrays.stream()\u65b9\u6cd5\u5c06\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6570\u7ec4\u8f6c\u6362\u4e3a\u6d41\uff0c\u7136\u540e\u4f7f\u7528mapToObj()\u65b9\u6cd5\u5c06\u6bcf\u4e2a\u5143\u7d20\u6620\u5c04\u5230\u5305\u88c5\u7c7b\u5bf9\u8c61\u3002 \u6700\u540e\uff0c\u4f7f\u7528toArray()\u65b9\u6cd5\u5c06\u6d41\u8f6c\u6362\u4e3a\u5bf9\u8c61\u6570\u7ec4\u3002 \u793a\u4f8b\uff1a int[] intArray = {1, 2, 3}; Integer[] intArrayWrapped = Arrays.stream(intArray) .mapToObj(Integer::valueOf) .toArray(Integer[]::new); \u767b\u5f55\u540e\u590d\u5236 \u5c01\u88c5\u7684\u597d\u5904\uff1a \u5b58\u50a8\u5bf9\u8c61\u5f15\u7528 \u6269\u5c55\u6570\u7ec4\u529f\u80fd\uff08\u4f8b\u5982\uff0c\u6392\u5e8f\u3001\u67e5\u627e\uff09 \u65b9\u4fbf\u6570\u7ec4\u7684\u4f20\u9012\u548c\u5904\u7406 \u4ee5\u4e0a\u5c31\u662fjava\u6570\u7ec4\u600e\u4e48\u5c01\u88c5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/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-65235","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65235","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=65235"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65235\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65235"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65235"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65235"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}