{"id":65432,"date":"2025-05-03T08:42:57","date_gmt":"2025-05-03T00:42:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65432\/"},"modified":"2025-05-03T08:42:57","modified_gmt":"2025-05-03T00:42:57","slug":"%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e8%bd%acint%e6%95%b0%e7%bb%84-java-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65432\/","title":{"rendered":"\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u8f6cint\u6570\u7ec4 java"},"content":{"rendered":"<blockquote><p>\n  \u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u8f6c\u6362\u4e3a int \u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 integer.parseint() \u9010\u4e2a\u89e3\u6790\u5e76\u8f6c\u6362\u5b57\u7b26\u4e32\u5143\u7d20\u3002\u4f7f\u7528 java 8 \u6d41 api \u548c integer::parseint() lambda \u8868\u8fbe\u5f0f\u3002\u4f7f\u7528 apache commons lang \u5e93\u7684 integerutils.tointarray(string[]) \u65b9\u6cd5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111300521333768.jpg\" class=\"aligncenter\" title=\"\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u8f6cint\u6570\u7ec4 java\u63d2\u56fe\" alt=\"\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u8f6cint\u6570\u7ec4 java\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u8f6c\u6362\u4e3a int \u6570\u7ec4<\/strong><\/p>\n<p>\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u8f6c\u6362\u4e3a int \u6570\u7ec4\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u7f16\u7a0b\u4efb\u52a1\u3002Java \u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<p><strong>\u4f7f\u7528 Integer.parseInt()<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5\u9010\u4e2a\u89e3\u6790\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5143\u7d20\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a int \u7c7b\u578b\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String[] strArr = {\"1\", \"2\", \"3\"};\nint[] intArr = new int[strArr.length];\n\nfor (int i = 0; i &lt; strArr.length; i++) {\n    intArr[i] = Integer.parseInt(strArr[i]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Stream \u548c Integer::parseInt()<\/strong><\/p>\n<p>Java 8 \u53ca\u66f4\u9ad8\u7248\u672c\u53ef\u4ee5\u4f7f\u7528\u6d41 API \u6765\u5904\u7406\u6b64\u4efb\u52a1\u3002Integer::parseInt() \u65b9\u6cd5\u53ef\u4ee5\u4f5c\u4e3a map \u51fd\u6570\u7684lambda\u8868\u8fbe\u5f0f\u4f7f\u7528\u3002<\/p>\n<pre>String[] strArr = {\"1\", \"2\", \"3\"};\nint[] intArr = Arrays.stream(strArr)\n        .map(Integer::parseInt)\n        .toArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Apache Commons Lang<\/strong><\/p>\n<p>Apache Commons Lang \u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a IntegerUtils.toIntArray(String[]) \u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u8f6c\u6362\u4e3a int \u6570\u7ec4\u3002<\/p>\n<pre>import org.apache.commons.lang3.ArrayUtils;\n\nString[] strArr = {\"1\", \"2\", \"3\"};\nint[] intArr = ArrayUtils.toIntArray(strArr);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8f6cint\u6570\u7ec4 java\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>\u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u8f6c\u6362\u4e3a int \u6570\u7ec4\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 integer.parseint() \u9010\u4e2a\u89e3\u6790\u5e76\u8f6c\u6362\u5b57\u7b26\u4e32\u5143\u7d20\u3002\u4f7f\u7528 java 8 \u6d41 api \u548c integer::parseint() lambda \u8868\u8fbe\u5f0f\u3002\u4f7f\u7528 apache commons lang \u5e93\u7684 integerutils.tointarray(string[]) \u65b9\u6cd5\u3002 \u5982\u4f55\u5c06\u8f6c\u6362\u4e3a int \u6570\u7ec4 \u5c06\u5b57\u7b26\u4e32\u6570\u7ec4\u8f6c\u6362\u4e3a int \u6570\u7ec4\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u7f16\u7a0b\u4efb\u52a1\u3002Java \u63d0\u4f9b\u4e86\u51e0\u79cd\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002 \u4f7f\u7528 Integer.parseInt() \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5\u9010\u4e2a\u89e3\u6790\u6bcf\u4e2a\u5b57\u7b26\u4e32\u5143\u7d20\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a int \u7c7b\u578b\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String[] strArr = {&#8220;1&#8221;, &#8220;2&#8221;, &#8220;3&#8221;}; int[] intArr = new int[strArr.length]; for (int i = 0; i &lt; strArr.length; i++) { [&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-65432","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65432","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=65432"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65432\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}