{"id":38590,"date":"2024-11-26T17:07:18","date_gmt":"2024-11-26T09:07:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/38590\/"},"modified":"2024-11-26T17:07:18","modified_gmt":"2024-11-26T09:07:18","slug":"java%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e6%af%94%e8%be%83%e7%a9%ba%e6%a0%bc%e5%90%8e%e7%9a%84%e6%95%b0","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/38590\/","title":{"rendered":"JAVA\u6570\u7ec4\u600e\u4e48\u6bd4\u8f83\u7a7a\u683c\u540e\u7684\u6570"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u6bd4\u8f83\u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a\u53bb\u9664\u5c3e\u90e8\u7a7a\u683c\uff1a\u4f7f\u7528 string.trim() \u65b9\u6cd5\u3002\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a\u4f7f\u7528 integer.parseint() \u65b9\u6cd5\u3002\u6bd4\u8f83\u6570\u5b57\uff1a\u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08\u5982 ==\u3001&gt;\u3001\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/15\/2024111503340735922.jpg\" class=\"aligncenter\" title=\"JAVA\u6570\u7ec4\u600e\u4e48\u6bd4\u8f83\u7a7a\u683c\u540e\u7684\u6570\u63d2\u56fe\" alt=\"JAVA\u6570\u7ec4\u600e\u4e48\u6bd4\u8f83\u7a7a\u683c\u540e\u7684\u6570\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6bd4\u8f83 Java \u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u6bd4\u8f83\u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u53bb\u9664\u7a7a\u683c\uff1a<\/strong> \u4f7f\u7528 String.trim() \u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u5c3e\u90e8\u7684\u7a7a\u683c\u3002<\/li>\n<li> <strong>\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a<\/strong> \u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5\u5c06\u53bb\u9664\u7a7a\u683c\u540e\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/li>\n<li> <strong>\u6bd4\u8f83\u6570\u5b57\uff1a<\/strong> \u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08\u5982 ==\u3001&gt;,<\/li>\n<\/ol>\n<p><strong>\u4ee3\u7801\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4\nString[] arr = {\"123 \", \"456  \", \"789 \"};\n\n\/\/ \u6bd4\u8f83\u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57\nfor (String s : arr) {\n    int num = Integer.parseInt(s.trim());\n    \/\/ \u6bd4\u8f83 num \u4e0e\u5176\u4ed6\u6570\u5b57\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\uff0cInteger.parseInt() \u65b9\u6cd5\u5c06\u629b\u51fa NumberFormatException\u3002<\/li>\n<li>trim() \u65b9\u6cd5\u4ec5\u53bb\u9664\u5c3e\u90e8\u7a7a\u683c\uff0c\u4e0d\u53bb\u9664\u5b57\u7b26\u4e32\u524d\u9762\u7684\u7a7a\u683c\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u5728\u6bd4\u8f83\u524d\u6e05\u9664\u6240\u6709\u7a7a\u683c\uff0c\u53ef\u4ee5\u4f7f\u7528 String.replaceAll(&#8220;s+&#8221;, &#8220;&#8221;);\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fJAVA\u6570\u7ec4\u600e\u4e48\u6bd4\u8f83\u7a7a\u683c\u540e\u7684\u6570\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>\u5728 java \u4e2d\u6bd4\u8f83\u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a\u53bb\u9664\u5c3e\u90e8\u7a7a\u683c\uff1a\u4f7f\u7528 string.trim() \u65b9\u6cd5\u3002\u8f6c\u6362\u4e3a\u6570\u5b57\uff1a\u4f7f\u7528 integer.parseint() \u65b9\u6cd5\u3002\u6bd4\u8f83\u6570\u5b57\uff1a\u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08\u5982 ==\u3001&gt;\u3001 \u5982\u4f55\u6bd4\u8f83 Java \u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57 \u5728 Java \u4e2d\uff0c\u6bd4\u8f83\u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u53bb\u9664\u7a7a\u683c\uff1a \u4f7f\u7528 String.trim() \u65b9\u6cd5\u53bb\u9664\u5b57\u7b26\u4e32\u5c3e\u90e8\u7684\u7a7a\u683c\u3002 \u8f6c\u6362\u4e3a\u6570\u5b57\uff1a \u4f7f\u7528 Integer.parseInt() \u65b9\u6cd5\u5c06\u53bb\u9664\u7a7a\u683c\u540e\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u3002 \u6bd4\u8f83\u6570\u5b57\uff1a \u4f7f\u7528\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff08\u5982 ==\u3001&gt;, \u4ee3\u7801\u793a\u4f8b\uff1a \/\/ \u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u4e32\u6570\u7ec4 String[] arr = {&#8220;123 &#8220;, &#8220;456 &#8220;, &#8220;789 &#8220;}; \/\/ \u6bd4\u8f83\u6570\u7ec4\u4e2d\u5b57\u7b26\u4e32\u5c3e\u90e8\u7a7a\u683c\u540e\u7684\u6570\u5b57 for (String s : arr) { int num = Integer.parseInt(s.trim()); \/\/ \u6bd4\u8f83 num \u4e0e\u5176\u4ed6\u6570\u5b57 } \u767b\u5f55\u540e\u590d\u5236 [&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-38590","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38590","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=38590"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/38590\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=38590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=38590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=38590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}