{"id":65460,"date":"2025-05-03T10:21:17","date_gmt":"2025-05-03T02:21:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/65460\/"},"modified":"2025-05-03T10:21:17","modified_gmt":"2025-05-03T02:21:17","slug":"java%e5%ad%97%e7%ac%a6%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e8%bd%ac%e6%8d%a2%e6%88%90%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/65460\/","title":{"rendered":"Java\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8f6c\u6362\u6210\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5728 java \u4e2d\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u7ec4\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a\u4f7f\u7528 string.valueof() \u65b9\u6cd5\uff1a\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 for \u5faa\u73af\u548c string.charat() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u6570\u7ec4\u3002\u4f7f\u7528 character.getnumericvalue() \u65b9\u6cd5\uff1a\u904d\u5386\u5b57\u7b26\u6570\u7ec4\u5e76\u4f7f\u7528 character.getnumericvalue() \u65b9\u6cd5\u83b7\u53d6\u6570\u5b57\u503c\u3002\u5c06\u6570\u5b57\u503c\u5b58\u50a8\u5728\u6570\u5b57\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528 ascii \u7801\uff1a\u83b7\u53d6\u6bcf\u4e2a\u5b57\u7b26\u7684 ascii \u7801\u3002\u5c06 ascii \u7801\u5b58\u50a8\u5728\u6570\u5b57\u6570\u7ec4\u4e2d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/13\/2024111301304750002.jpg\" class=\"aligncenter\" title=\"Java\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8f6c\u6362\u6210\u6570\u7ec4\u63d2\u56fe\" alt=\"Java\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8f6c\u6362\u6210\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u7ec4<\/strong><\/p>\n<p>\u8981\u5c06 Java \u4e2d\u7684\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528 String.valueOf() \u65b9\u6cd5<\/strong><\/p>\n<p>\u6b64\u65b9\u6cd5\u8fd4\u56de\u5b57\u7b26\u6570\u7ec4\u8868\u793a\u7684\u5b57\u7b26\u4e32\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String str = String.valueOf(charArray);\nint[] array = new int[str.length()];\nfor (int i = 0; i &lt; str.length(); i++) {\n    array[i] = str.charAt(i);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 Character.getNumericValue() \u65b9\u6cd5<\/strong><\/p>\n<p>\u6b64\u65b9\u6cd5\u8fd4\u56de\u6307\u5b9a\u5b57\u7b26\u7684\u6570\u5b57\u503c\u3002\u901a\u8fc7\u904d\u5386\u5b57\u7b26\u6570\u7ec4\u5e76\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u5b57\u6570\u7ec4\uff1a<\/p>\n<pre>int[] array = new int[charArray.length];\nfor (int i = 0; i &lt; charArray.length; i++) {\n    array[i] = Character.getNumericValue(charArray[i]);\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 ASCII \u7801<\/strong><\/p>\n<p>ASCII \u7801\u4e3a\u6bcf\u4e2a\u5b57\u7b26\u5206\u914d\u4e86\u4e00\u4e2a\u6570\u5b57\u503c\u3002\u901a\u8fc7\u83b7\u53d6\u6bcf\u4e2a\u5b57\u7b26\u7684 ASCII \u7801\uff0c\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u5b57\u6570\u7ec4\uff1a<\/p>\n<pre>int[] array = new int[charArray.length];\nfor (int i = 0; i &lt; charArray.length; i++) {\n    array[i] = (int) charArray[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>char[] charArray = {'1', '2', '3', '4', '5'};\n\n\/\/ \u4f7f\u7528 String.valueOf() \u65b9\u6cd5\nString str = String.valueOf(charArray);\nint[] array = new int[str.length()];\nfor (int i = 0; i &lt; str.length(); i++) {\n    array[i] = str.charAt(i);\n}\n\n\/\/ \u4f7f\u7528 Character.getNumericValue() \u65b9\u6cd5\nint[] array2 = new int[charArray.length];\nfor (int i = 0; i &lt; charArray.length; i++) {\n    array2[i] = Character.getNumericValue(charArray[i]);\n}\n\n\/\/ \u4f7f\u7528 ASCII \u7801\nint[] array3 = new int[charArray.length];\nfor (int i = 0; i &lt; charArray.length; i++) {\n    array3[i] = (int) charArray[i];\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fJava\u5b57\u7b26\u6570\u7ec4\u600e\u4e48\u8f6c\u6362\u6210\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>\u8981\u5728 java \u4e2d\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u7ec4\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a\u4f7f\u7528 string.valueof() \u65b9\u6cd5\uff1a\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 for \u5faa\u73af\u548c string.charat() \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\u6570\u7ec4\u3002\u4f7f\u7528 character.getnumericvalue() \u65b9\u6cd5\uff1a\u904d\u5386\u5b57\u7b26\u6570\u7ec4\u5e76\u4f7f\u7528 character.getnumericvalue() \u65b9\u6cd5\u83b7\u53d6\u6570\u5b57\u503c\u3002\u5c06\u6570\u5b57\u503c\u5b58\u50a8\u5728\u6570\u5b57\u6570\u7ec4\u4e2d\u3002\u4f7f\u7528 ascii \u7801\uff1a\u83b7\u53d6\u6bcf\u4e2a\u5b57\u7b26\u7684 ascii \u7801\u3002\u5c06 ascii \u7801\u5b58\u50a8\u5728\u6570\u5b57\u6570\u7ec4\u4e2d\u3002 Java \u4e2d\u5c06\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u7ec4 \u8981\u5c06 Java \u4e2d\u7684\u5b57\u7b26\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u7ec4\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a 1. \u4f7f\u7528 String.valueOf() \u65b9\u6cd5 \u6b64\u65b9\u6cd5\u8fd4\u56de\u5b57\u7b26\u6570\u7ec4\u8868\u793a\u7684\u5b57\u7b26\u4e32\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u7ec4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String str = String.valueOf(charArray); int[] array = new int[str.length()]; for (int i = 0; i &lt; str.length(); i++) { array[i] = str.charAt(i); } \u767b\u5f55\u540e\u590d\u5236 2. [&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-65460","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65460","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=65460"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/65460\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=65460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=65460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=65460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}