{"id":64604,"date":"2025-05-03T10:51:47","date_gmt":"2025-05-03T02:51:47","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64604\/"},"modified":"2025-05-03T10:51:47","modified_gmt":"2025-05-03T02:51:47","slug":"java%e6%80%8e%e4%b9%88%e5%b0%86%e4%b8%80%e4%b8%b2%e6%95%b0%e5%ad%97%e5%ad%98%e5%85%a5%e6%95%b0%e7%bb%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64604\/","title":{"rendered":"java\u600e\u4e48\u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u4f7f\u7528 java \u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528 integer.parseint() \u65b9\u6cd5\uff1a\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u8f6c\u6362\u5b50\u4e32\u4e3a int \u503c\uff0c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528 stream api\uff1a\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u8f6c\u6362\u4e3a\u6574\u6570\u6d41\uff0c\u6536\u96c6\u5230\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a\u5339\u914d\u6570\u5b57\uff0c\u63d0\u53d6\u5e76\u8f6c\u6362\u4e3a int \u503c\uff0c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/04\/2024110403124295131.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Java \u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4<\/strong><\/p>\n<p>\u5f53\u9700\u8981\u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u50a8\u5728\u4e00\u4e2a\u5bb9\u5668\u4e2d\u4ee5\u4fbf\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\u65f6\uff0c\u6570\u7ec4\u662f\u4e00\u4e2a\u6709\u7528\u7684\u5de5\u5177\u3002Java \u63d0\u4f9b\u4e86\u51e0\u79cd\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5<\/strong><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u5206\u5272\u5b57\u7b26\u4e32\u6210\u5305\u542b\u5355\u4e2a\u6570\u5b57\u7684\u5b50\u4e32\u3002<\/li>\n<li>\u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5\u5c06\u6bcf\u4e2a\u5b50\u4e32\u8f6c\u6362\u4e3a\u4e00\u4e2a int \u503c\u3002<\/li>\n<li>\u5c06\u8f6c\u6362\u540e\u7684\u6570\u5b57\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>String numbers = \"123456789\";\nString[] parts = numbers.split(\"\");\nint[] intArray = new int[parts.length];\nfor (int i = 0; i &lt; parts.length; i++) {\n    intArray[i] = Integer.parseInt(parts[i]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 Stream API<\/strong><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u4f7f\u7528 split() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u5206\u6210\u5b57\u7b26\u6570\u7ec4\u3002<\/li>\n<li>\u4f7f\u7528 mapToInt() \u65b9\u6cd5\u5c06\u5b57\u7b26\u6d41\u8f6c\u6362\u4e3a\u6574\u6570\u6d41\u3002<\/li>\n<li>\u5c06\u6574\u6570\u6d41\u6536\u96c6\u5230\u4e00\u4e2a\u6570\u7ec4\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>String numbers = \"123456789\";\nint[] intArray = numbers.chars().mapToInt(Character::getNumericValue).toArray();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6a21\u5f0f\u5339\u914d\u6570\u5b57\u3002<\/li>\n<li>\u63d0\u53d6\u5339\u914d\u9879\u5e76\u8f6c\u6362\u4e3a int \u503c\u3002<\/li>\n<li>\u5c06\u8f6c\u6362\u540e\u7684\u6570\u5b57\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>String numbers = \"123456789\";\nPattern pattern = Pattern.compile(\"\\d+\");\nMatcher matcher = pattern.matcher(numbers);\nint[] intArray = new int[matcher.groupCount()];\nint i = 0;\nwhile (matcher.find()) {\n    intArray[i++] = Integer.parseInt(matcher.group());\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\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>\u4f7f\u7528 java \u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\u7684\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528 integer.parseint() \u65b9\u6cd5\uff1a\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u8f6c\u6362\u5b50\u4e32\u4e3a int \u503c\uff0c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528 stream api\uff1a\u5206\u5272\u5b57\u7b26\u4e32\uff0c\u8f6c\u6362\u4e3a\u6574\u6570\u6d41\uff0c\u6536\u96c6\u5230\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff1a\u5339\u914d\u6570\u5b57\uff0c\u63d0\u53d6\u5e76\u8f6c\u6362\u4e3a int \u503c\uff0c\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002 \u5982\u4f55\u4f7f\u7528 Java \u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4 \u5f53\u9700\u8981\u5c06\u4e00\u4e32\u6570\u5b57\u5b58\u50a8\u5728\u4e00\u4e2a\u5bb9\u5668\u4e2d\u4ee5\u4fbf\u8fdb\u884c\u8fdb\u4e00\u6b65\u5904\u7406\u65f6\uff0c\u6570\u7ec4\u662f\u4e00\u4e2a\u6709\u7528\u7684\u5de5\u5177\u3002Java \u63d0\u4f9b\u4e86\u51e0\u79cd\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u4e00\u4e32\u6570\u5b57\u5b58\u5165\u6570\u7ec4\u7684\u65b9\u6cd5\u3002 \u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5 \u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5206\u5272\u5b57\u7b26\u4e32\u6210\u5305\u542b\u5355\u4e2a\u6570\u5b57\u7684\u5b50\u4e32\u3002 \u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5\u5c06\u6bcf\u4e2a\u5b50\u4e32\u8f6c\u6362\u4e3a\u4e00\u4e2a int \u503c\u3002 \u5c06\u8f6c\u6362\u540e\u7684\u6570\u5b57\u5b58\u50a8\u5728\u6570\u7ec4\u4e2d\u3002 \u793a\u4f8b\u4ee3\u7801\uff1a String numbers = &#8220;123456789&#8221;; String[] parts = numbers.split(&#8220;&#8221;); int[] intArray = new int[parts.length]; for (int i = 0; i &lt; parts.length; i++) { intArray[i] = Integer.parseInt(parts[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-64604","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64604","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=64604"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64604\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}