{"id":1384,"date":"2025-08-21T16:23:07","date_gmt":"2025-08-21T08:23:07","guid":{"rendered":"https:\/\/zero-zl.cn\/?p=1384"},"modified":"2025-08-21T22:21:37","modified_gmt":"2025-08-21T14:21:37","slug":"java%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/zero-zl.cn\/index.php\/2025\/08\/21\/java%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b\/","title":{"rendered":"Java\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"_1\u3001java-\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u90fd\u6709\u54ea\u4e9b\u5404\u5360\u51e0\u4e2a\u5b57\u8282\"><a href=\"#_1\u3001java-\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u90fd\u6709\u54ea\u4e9b\u5404\u5360\u51e0\u4e2a\u5b57\u8282\">1\u3001Java \u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u90fd\u6709\u54ea\u4e9b\u5404\u5360\u51e0\u4e2a\u5b57\u8282\uff1f<\/a><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/zero-zl.cn\/wp-content\/uploads\/2025\/08\/image-20210712152020611-B8jeLl50.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"345\" data-original=\"https:\/\/zero-zl.cn\/wp-content\/uploads\/2025\/08\/image-20210712152020611-B8jeLl50.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1446\"  sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><\/div><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/zero-zl.cn\/wp-content\/uploads\/2025\/08\/image-20210712152043638-BpUVxIy-.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"990\" height=\"36\" data-original=\"https:\/\/zero-zl.cn\/wp-content\/uploads\/2025\/08\/image-20210712152043638-BpUVxIy-.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-1447\"  sizes=\"auto, (max-width: 990px) 100vw, 990px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_2\u3001string-\u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u5417\"><a href=\"#_2\u3001string-\u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u5417\">2\u3001String \u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u5417\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u4e0d\u662f\uff0cString\u662f\u5f15\u7528\u7c7b\u578b\uff0c\u5e95\u5c42\u662f\u7528char\u6570\u7ec4\u5b9e\u73b0\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Java \u4e2d\u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u53ea\u67098 \u4e2a\uff1a<code>byte<\/code>\u3001<code>short<\/code>\u3001<code>int<\/code>\u3001<code>long<\/code>\u3001<code>float<\/code>\u3001<code>double<\/code>\u3001<code>char<\/code>\u3001<code>boolean<\/code>\uff1b\u9664\u4e86\u57fa\u672c\u7c7b\u578b\uff08primitive type\uff09\uff0c\u5269\u4e0b\u7684\u90fd\u662f\u5f15\u7528\u7c7b\u578b\uff08referencetype\uff09\uff0c Java 5 \u4ee5\u540e\u5f15\u5165\u7684\u679a\u4e3e\u7c7b\u578b\u4e5f\u7b97\u662f\u4e00\u79cd\u6bd4\u8f83\u7279\u6b8a\u7684\u5f15\u7528\u7c7b\u578b\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_3\u3001\u8fd0\u884cshort-s1-1-s1-s1-1-\u4f1a\u51fa\u73b0\u4ec0\u4e48\u7ed3\u679c-\u8fd0\u884cshort-s1-1-s1-1-\u53c8\u4f1a\u51fa\u73b0\u4ec0\u4e48\u7ed3\u679c\"><a href=\"#_3\u3001\u8fd0\u884cshort-s1-1-s1-s1-1-\u4f1a\u51fa\u73b0\u4ec0\u4e48\u7ed3\u679c-\u8fd0\u884cshort-s1-1-s1-1-\u53c8\u4f1a\u51fa\u73b0\u4ec0\u4e48\u7ed3\u679c\">3\u3001\u8fd0\u884cshort s1 = 1\uff0c s1 = s1 + 1 \uff1b\u4f1a\u51fa\u73b0\u4ec0\u4e48\u7ed3\u679c\uff1f\u8fd0\u884cshort s1 = 1; s1 += 1 \uff1b\u53c8\u4f1a\u51fa\u73b0\u4ec0\u4e48\u7ed3\u679c\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ul class=\"wp-block-list\">\n<li>\u8fd0\u884c\u7b2c\u4e00\u4e2a\u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a1\u662f<code>int<\/code>\u7c7b\u578b\uff0c\u800cs\u662f<code>short<\/code>\u7c7b\u578b\uff0c\u901a\u8fc7+\u8fd0\u7b97\u540es1\u81ea\u52a8\u8f6c\u6362\u6210<code>int<\/code>\u578b\u3002\u9519\u8bef\u63d0\u793a\uff1aError:(21, 17) java: \u4e0d\u517c\u5bb9\u7684\u7c7b\u578b: \u4ece<code>int<\/code>\u8f6c\u6362\u5230<code>short<\/code>\u53ef\u80fd\u4f1a\u6709\u635f\u5931<\/li>\n\n\n\n<li>\u8fd0\u884c\u7b2c\u4e8c\u4e2a\u662f\u6b63\u786e\u7684\uff0cs1=2\uff0c+1\u662f<code>int<\/code>\u7c7b\u578b\u7684\u64cd\u4f5c\uff0cs1\u81ea\u52a8\u8f6c\u6362<code>int<\/code>\u7c7b\u578b<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_4\u3001int-\u548cinteger-\u6709\u4ec0\u4e48\u533a\u522b\"><a href=\"#_4\u3001int-\u548cinteger-\u6709\u4ec0\u4e48\u533a\u522b\">4\u3001int \u548cInteger \u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Java \u662f\u4e00\u4e2a\u8fd1\u4e4e\u7eaf\u6d01\u7684\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u8bed\u8a00\uff0c\u4f46\u662f\u4e3a\u4e86\u7f16\u7a0b\u7684\u65b9\u4fbf\u8fd8\u662f\u5f15\u5165\u4e86\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u662f\u4e3a\u4e86\u80fd\u591f\u5c06\u8fd9\u4e9b\u57fa\u672c\u6570\u636e\u7c7b\u578b\u5f53\u6210\u5bf9\u8c61\u64cd\u4f5c\uff0cJava \u4e3a\u6bcf\u4e00\u4e2a\u57fa\u672c\u6570\u636e\u7c7b\u578b\u90fd\u5f15\u5165\u4e86\u5bf9\u5e94\u7684\u5305\u88c5\u7c7b\u578b\uff08wrapper class\uff09\uff0cint \u7684\u5305\u88c5\u7c7b\u5c31\u662fInteger\uff0c\u4eceJava 5 \u5f00\u59cb\u5f15\u5165\u4e86\u81ea\u52a8\u88c5\u7bb1\/\u62c6\u7bb1\u673a\u5236\uff0c\u4f7f\u5f97\u4e8c\u8005\u53ef\u4ee5\u76f8\u4e92\u8f6c\u6362\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u539f\u59cb\u7c7b\u578b: boolean\uff0c char\uff0c byte\uff0c short\uff0c int\uff0c long\uff0c float\uff0cdouble<\/li>\n\n\n\n<li>\u5305\u88c5\u7c7b\u578b\uff1aBoolean\uff0cCharacter\uff0cByte\uff0cShort\uff0cInteger\uff0cLong\uff0cFloat\uff0cDouble<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>public class AutomaticUnboxing {\n    public static void main(String&#91;] args) {\n        Integer a1 = 100,a2 = 100,z3 = 139, z4 =139;\n        System.out.println(a1 == a2); \/\/true\n        System.out.println(z3 == z4); \/\/false\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5982\u679c\u6574\u578b\u5b57\u9762\u91cf\u7684\u503c\u5728-128 \u5230127 \u4e4b\u95f4\uff0c\u90a3\u4e48\u4e0d\u4f1anew \u65b0\u7684Integer\u5bf9\u8c61\uff0c\u800c\u662f\u76f4\u63a5\u5f15\u7528\u5e38\u91cf\u6c60\u4e2d\u7684Integer \u5bf9\u8c61<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_5\u3001float-f-3-4-\u662f\u5426\u6b63\u786e\"><a href=\"#_5\u3001float-f-3-4-\u662f\u5426\u6b63\u786e\">5\u3001float f=3.4;\u662f\u5426\u6b63\u786e\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u4e0d\u6b63\u786e\u30023.4\u662f\u53cc\u7cbe\u5ea6\u3002\u5c06\u53cc\u7cbe\u5ea6\u578b\uff08double\uff09 \u8d4b\u503c\u7ed9\u6d6e\u70b9\u578b\uff08float\uff09\u5c5e\u4e8e\u4e0b\u8f6c\u578b\uff08 down-casting\uff0c\u4e5f\u79f0\u4e3a\u7a84\u5316\uff09\u4f1a\u9020\u6210\u7cbe\u5ea6\u635f\u5931\uff0c\u56e0\u6b64\u9700\u8981\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<code>float f =(float)3.4<\/code>; \u6216\u8005\u5199\u6210<code>float f =3.4F<\/code>;\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_6\u3001\u7528\u6700\u9ad8\u6548\u7387\u7684\u65b9\u6cd5\u7b97\u51fa2-\u4e58\u4ee58-\u7b49\u4e8e\u591a\u5c11\u3002\"><a href=\"#_6\u3001\u7528\u6700\u9ad8\u6548\u7387\u7684\u65b9\u6cd5\u7b97\u51fa2-\u4e58\u4ee58-\u7b49\u4e8e\u591a\u5c11\u3002\">6\u3001\u7528\u6700\u9ad8\u6548\u7387\u7684\u65b9\u6cd5\u7b97\u51fa2 \u4e58\u4ee58 \u7b49\u4e8e\u591a\u5c11\u3002<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u79fb\u4f4d\u8fd0\u7b97\u7b26\uff1a<code>int i = 2 &lt;&lt; 3<\/code>;<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_7\u3001string-\u7c7b\u5e38\u7528\u65b9\u6cd5\"><a href=\"#_7\u3001string-\u7c7b\u5e38\u7528\u65b9\u6cd5\">7\u3001String \u7c7b\u5e38\u7528\u65b9\u6cd5<\/a><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6cd5<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-length.html\" target=\"_blank\" rel=\"noreferrer noopener\">int length()<\/a><\/td><td>\u8fd4\u56de\u6b64\u5b57\u7b26\u4e32\u7684\u957f\u5ea6<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-indexof.html\" target=\"_blank\" rel=\"noreferrer noopener\">int indexOf(int ch)<\/a><\/td><td>\u8fd4\u56de\u6307\u5b9a\u5b57\u7b26\u5728\u6b64\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u5904\u7684\u7d22\u5f15<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-indexof.html\" target=\"_blank\" rel=\"noreferrer noopener\">int indexOf(int ch, int fromIndex)<\/a><\/td><td>\u8fd4\u56de\u5728\u6b64\u5b57\u7b26\u4e32\u4e2d\u7b2c\u4e00\u6b21\u51fa\u73b0\u6307\u5b9a\u5b57\u7b26\u5904\u7684\u7d22\u5f15\uff0c\u4ece\u6307\u5b9a\u7684\u7d22\u5f15\u5f00\u59cb\u641c\u7d22<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-lastindexof.html\" target=\"_blank\" rel=\"noreferrer noopener\">int lastIndexOf(int ch)<\/a><\/td><td>\u8fd4\u56de\u6307\u5b9a\u5b57\u7b26\u5728\u6b64\u5b57\u7b26\u4e32\u4e2d\u6700\u540e\u4e00\u6b21\u51fa\u73b0\u5904\u7684\u7d22\u5f15<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-concat.html\" target=\"_blank\" rel=\"noreferrer noopener\">String concat(String str)<\/a><\/td><td>\u5c06\u6307\u5b9a\u5b57\u7b26\u4e32\u8fde\u63a5\u5230\u6b64\u5b57\u7b26\u4e32\u7684\u7ed3\u5c3e\u3002<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-endswith.html\" target=\"_blank\" rel=\"noreferrer noopener\">boolean endsWith(String suffix)<\/a><\/td><td>\u6d4b\u8bd5\u6b64\u5b57\u7b26\u4e32\u662f\u5426\u4ee5\u6307\u5b9a\u7684\u540e\u7f00\u7ed3\u675f\u3002<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-replace.html\" target=\"_blank\" rel=\"noreferrer noopener\">String replace(char oldChar, char newChar)<\/a><\/td><td>\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u5b83\u662f\u901a\u8fc7\u7528 newChar \u66ff\u6362\u6b64\u5b57\u7b26\u4e32\u4e2d\u51fa\u73b0\u7684\u6240\u6709 oldChar \u5f97\u5230\u7684\u3002<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-split.html\" target=\"_blank\" rel=\"noreferrer noopener\">String[] split(String regex)<\/a><\/td><td>\u6839\u636e\u7ed9\u5b9a\u6b63\u5219\u8868\u8fbe\u5f0f\u7684\u5339\u914d\u62c6\u5206\u6b64\u5b57\u7b26\u4e32\u3002<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-substring.html\" target=\"_blank\" rel=\"noreferrer noopener\">String substring(int beginIndex)<\/a><\/td><td>\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u5b83\u662f\u6b64\u5b57\u7b26\u4e32\u7684\u4e00\u4e2a\u5b50\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-trim.html\" target=\"_blank\" rel=\"noreferrer noopener\">String trim()<\/a><\/td><td>\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u526f\u672c\uff0c\u5ffd\u7565\u524d\u5bfc\u7a7a\u767d\u548c\u5c3e\u90e8\u7a7a\u767d<\/td><\/tr><tr><td><a href=\"https:\/\/www.runoob.com\/java\/java-string-equals.html\" target=\"_blank\" rel=\"noreferrer noopener\">boolean equals(Object anObject)<\/a><\/td><td>\u5c06\u6b64\u5b57\u7b26\u4e32\u4e0e\u6307\u5b9a\u7684\u5bf9\u8c61\u6bd4\u8f83\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_8\u3001string-\u3001-stringbuffer-\u3001-stringbuilder-\u7684\u533a\u522b\"><a href=\"#_8\u3001string-\u3001-stringbuffer-\u3001-stringbuilder-\u7684\u533a\u522b\">8\u3001String \u3001 StringBuffer \u3001 StringBuilder \u7684\u533a\u522b\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\"><strong>1\u3001\u53ef\u53d8\u4e0e\u4e0d\u53ef\u53d8<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">String\uff1a\u5b57\u7b26\u4e32\u5e38\u91cf\uff0c\u5728\u4fee\u6539\u65f6\u4e0d\u6539\u53d8\u81ea\u8eab\uff1b\u82e5\u4fee\u6539\uff0c\u7b49\u4e8e\u751f\u6210\u65b0\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">StringBuffer\uff1a\u5728\u4fee\u6539\u65f6\u4f1a\u6539\u53d8\u5bf9\u8c61\u81ea\u8eab\uff0c\u6bcf\u6b21\u64cd\u4f5c\u90fd\u662f\u5bf9 StringBuffer \u5bf9\u8c61\u672c\u8eab\u8fdb\u884c\u4fee\u6539\uff0c\u4e0d\u662f\u751f\u6210\u65b0\u7684\u5bf9\u8c61\uff1b\u4f7f\u7528\u573a\u666f\uff1a\u5bf9\u5b57\u7b26\u4e32\u7ecf\u5e38\u6539\u53d8\u60c5\u51b5\u4e0b\uff0c\u4e3b\u8981\u65b9\u6cd5\uff1a append insert \uff08\uff09\u7b49\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2\u3001\u7ebf\u7a0b\u662f\u5426\u5b89\u5168<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">String\uff1a\u5bf9\u8c61\u5b9a\u4e49\u540e\u4e0d\u53ef\u53d8\uff0c\u7ebf\u7a0b\u5b89\u5168\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">StringBuffer\uff1a\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff08\u5bf9\u8c03\u7528\u65b9\u6cd5\u52a0\u5165\u540c\u6b65\u9501\uff09\uff0c\u6267\u884c\u6548\u7387\u8f83\u6162\uff0c\u9002\u7528\u4e8e\u591a\u7ebf\u7a0b\u4e0b\u64cd\u4f5c\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u5927\u91cf\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">StringBuilder \uff1a\u662f\u7ebf\u7a0b\u4e0d\u5b89\u5168\u7684\uff0c\u9002\u7528\u4e8e\u5355\u7ebf\u7a0b\u4e0b\u64cd\u4f5c\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u5927\u91cf\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3\u3001\u5171\u540c\u70b9<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">StringBuilder \u4e0e StringBuffer \u6709\u516c\u5171\u7236\u7c7b AbstractStringBuilder(\u62bd\u8c61\u7c7b)\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public final class StringBuilder extends AbstractStringBuilder implements java.io.Serializable, CharSequence\n\npublic final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, CharSequence<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">StringBuilder\u3001StringBuffer \u7684\u65b9\u6cd5\u90fd\u4f1a\u8c03\u7528 AbstractStringBuilder \u4e2d\u7684\u516c\u5171\u65b9\u6cd5\uff0c\u5982 super.append(&#8230;)\u3002\u53ea\u662f StringBuffer \u4f1a\u5728\u65b9\u6cd5\u4e0a\u52a0 <strong>synchronized<\/strong> \u5173\u952e\u5b57\uff0c\u8fdb\u884c\u540c\u6b65\u3002\u6700\u540e\uff0c\u5982\u679c\u7a0b\u5e8f\u4e0d\u662f\u591a\u7ebf\u7a0b\u7684\uff0c\u90a3\u4e48\u4f7f\u7528StringBuilder \u6548\u7387\u9ad8\u4e8eStringBuffer\u3002<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5bf9\u4e8e\u4e09\u8005\u4f7f\u7528\u7684\u603b\u7ed3<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u8981\u64cd\u4f5c\u5c11\u91cf\u7684\u6570\u636e\u7528 = String<\/li>\n\n\n\n<li>\u5355\u7ebf\u7a0b\u64cd\u4f5c\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u4e0b\u64cd\u4f5c\u5927\u91cf\u6570\u636e = StringBuilder<\/li>\n\n\n\n<li>\u591a\u7ebf\u7a0b\u64cd\u4f5c\u5b57\u7b26\u4e32\u7f13\u51b2\u533a\u4e0b\u64cd\u4f5c\u5927\u91cf\u6570\u636e = StringBuffffer<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_9\u3001-while-\u548cdo-while-\u6709\u4ec0\u4e48\u533a\u522b\"><a href=\"#_9\u3001-while-\u548cdo-while-\u6709\u4ec0\u4e48\u533a\u522b\">9\u3001 while \u548cdo while \u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">while\u662f\u5148\u5224\u65ad\u518d\u6267\u884c\uff1bdo&#8230;while\u662f\u5148\u6267\u884c\u518d\u5224\u65ad\uff0c\u540c\u7b49\u6761\u4ef6\u4e0b\uff0c\u540e\u8005\u591a\u6267\u884c\u4e86\u4e00\u6b21\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_10\u3001switch-\u8bed\u53e5\u80fd\u5426\u4f5c\u7528\u5728byte-\u3001long-\u3001string-\u4e0a\"><a href=\"#_10\u3001switch-\u8bed\u53e5\u80fd\u5426\u4f5c\u7528\u5728byte-\u3001long-\u3001string-\u4e0a\">10\u3001switch \u8bed\u53e5\u80fd\u5426\u4f5c\u7528\u5728byte \u3001long \u3001String \u4e0a\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ul class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u7528\u5728<code>byte\u3001int\u3001short\u3001char<\/code>\u4ee5\u53ca\u5b83\u4eec\u7684\u5c01\u88c5\u7c7b\u4e0a<\/li>\n\n\n\n<li>\u4e0d\u80fd\u7528\u5728\u5176\u4ed6\u57fa\u672c\u7c7b\u578b\u4e0a<code>long\u3001double\u3001float\u3001boolean<\/code>\u4ee5\u53ca\u5c01\u88c5\u7c7b<\/li>\n\n\n\n<li>jdk1.7\u53ca\u4ee5\u4e0a\uff0c\u53ef\u4ee5\u7528\u4ee5\u5b57\u7b26\u4e32<\/li>\n\n\n\n<li>\u53ef\u4ee5\u7528\u4e8e\u679a\u4e3e\u7c7b\u578b<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_11\u3001string-s-new-string-xyz-\u521b\u5efa\u4e86\u51e0\u4e2astring-\u5bf9\u8c61-\u4e8c\u8005\u4e4b\u95f4\u518d\u4ec0\u4e48\u533a\u522b\u3002\"><a href=\"#_11\u3001string-s-new-string-xyz-\u521b\u5efa\u4e86\u51e0\u4e2astring-\u5bf9\u8c61-\u4e8c\u8005\u4e4b\u95f4\u518d\u4ec0\u4e48\u533a\u522b\u3002\">11\u3001<code>String s \uff1dnew String(\"xyz\")\uff1b<\/code>\uff0c\u521b\u5efa\u4e86\u51e0\u4e2aString \u5bf9\u8c61\uff1f\u4e8c\u8005\u4e4b\u95f4\u518d\u4ec0\u4e48\u533a\u522b\u3002<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u521b\u5efa\u4e862\u4e2a\u5bf9\u8c61\uff0c\u4e00\u4e2a\u662f\u5185\u5b58\u4e2d\u7684\u201cxyz\u201d\uff0c\u8fd8\u6709\u4e00\u4e2a\u662fs\uff0c\u6307\u5411xyz<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_12\u3001\u81ea\u52a8\u88c5\u7bb1\u4e0e\u62c6\u7bb1\"><a href=\"#_12\u3001\u81ea\u52a8\u88c5\u7bb1\u4e0e\u62c6\u7bb1\">12\u3001\u81ea\u52a8\u88c5\u7bb1\u4e0e\u62c6\u7bb1<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u81ea\u52a8\u88c5\u7bb1\uff1a\u5c06\u57fa\u672c\u7c7b\u578b\u7528\u4ed6\u4eec\u7684\u5f15\u7528\u7c7b\u578b\u5305\u88c5\u8d77\u6765<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u81ea\u52a8\u62c6\u7bb1\uff1a\u5c06\u5305\u88c5\u7c7b\u578b\u8f6c\u6362\u4e3a\u57fa\u672c\u7c7b\u578b<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_13\u3001math-round-11-5-\u7b49\u4e8e\u591a\u5c11-math-round-11-5-\u7b49\u4e8e\u591a\u5c11\"><a href=\"#_13\u3001math-round-11-5-\u7b49\u4e8e\u591a\u5c11-math-round-11-5-\u7b49\u4e8e\u591a\u5c11\">13\u3001Math.round(11.5) \u7b49\u4e8e\u591a\u5c11\uff1fMath.round(-11.5)\u7b49\u4e8e\u591a\u5c11\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Math.round(11.5)\u7684\u8fd4\u56de\u503c\u662f 12\uff0cMath.round(-11.5)\u7684\u8fd4\u56de\u503c\u662f-11\u3002<strong>\u56db\u820d\u4e94\u5165\u7684\u539f\u7406\u662f\u5728\u53c2\u6570\u4e0a\u52a0 0.5 \u7136\u540e\u8fdb\u884c\u4e0b\u53d6\u6574<\/strong>\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_14\u3001\u4e0b\u9762\u4ee3\u7801\u8fd0\u884c\u7ed3\u679c\u662f\u591a\u5c11\"><a href=\"#_14\u3001\u4e0b\u9762\u4ee3\u7801\u8fd0\u884c\u7ed3\u679c\u662f\u591a\u5c11\">14\u3001\u4e0b\u9762\u4ee3\u7801\u8fd0\u884c\u7ed3\u679c\u662f\u591a\u5c11\uff1f<\/a><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>int count = 0;\nfor (int k = 0; k &lt; 100; k++) {\n    count = count++;\n}\nSystem.out.println(count);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89e3\u6790<\/strong>\uff1a++\u662f\u5148\u8d4b\u503c\uff0c\u518d\u81ea\u589e\uff0c\u6240\u4ee5count\u6c38\u8fdc\u662f0<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_15\u3001java\u4e2d\u57fa\u672c\u7c7b\u578b\u662f\u5982\u4f55\u8f6c\u6362\u7684\"><a href=\"#_15\u3001java\u4e2d\u57fa\u672c\u7c7b\u578b\u662f\u5982\u4f55\u8f6c\u6362\u7684\">15\u3001Java\u4e2d\u57fa\u672c\u7c7b\u578b\u662f\u5982\u4f55\u8f6c\u6362\u7684\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u57fa\u672c\u7c7b\u578b\u7b49\u7ea7\u4ece\u4f4e\u5230\u9ad8\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>byte\u3001short\u3001int\u3001long\u3001float\u3001double<\/li>\n\n\n\n<li>char\u3001int\u3001long\u3001float\u3001double<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u81ea\u52a8\u8f6c\u6362\uff1a\u8fd0\u7b97\u8fc7\u7a0b\u4e2d\uff0c\u4f4e\u7ea7\u53ef\u4ee5\u81ea\u52a8\u5411\u9ad8\u7ea7\u8fdb\u884c\u8f6c\u6362<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f3a\u5236\u8f6c\u6362\uff1a\u9ad8\u7ea7\u9700\u8981\u5f3a\u5236\u8f6c\u6362\u6210\u4f4e\u7ea7\uff0c\u53ef\u80fd\u4f1a\u4e22\u5931\u7cbe\u5ea6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u89c4\u5219<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>= \u53f3\u8fb9\u5148\u81ea\u52a8\u8f6c\u6362\u6210\u8868\u8fbe\u5f0f\u4e2d\u6700\u9ad8\u7ea7\u7684\u6570\u636e\u7c7b\u578b\uff0c\u518d\u8fdb\u884c\u8fd0\u7b97\u3002\u6574\u578b\u7ecf\u8fc7\u8fd0\u7b97\u4f1a\u81ea\u52a8\u8f6c\u5316\u6700\u4f4e int \u7ea7\u522b\uff0c\u5982\u4e24\u4e2a char \u7c7b\u578b\u7684\u76f8\u52a0\uff0c\u5f97\u5230\u7684\u662f\u4e00\u4e2a int \u7c7b\u578b\u7684\u6570\u503c\u3002<\/li>\n\n\n\n<li>= \u5de6\u8fb9\u6570\u636e\u7c7b\u578b\u7ea7\u522b \u5927\u4e8e \u53f3\u8fb9\u6570\u636e\u7c7b\u578b\u7ea7\u522b\uff0c\u53f3\u8fb9\u4f1a\u81ea\u52a8\u5347\u7ea7<\/li>\n\n\n\n<li>= \u5de6\u8fb9\u6570\u636e\u7c7b\u578b\u7ea7\u522b \u5c0f\u4e8e \u53f3\u8fb9\u6570\u636e\u7c7b\u578b\u7ea7\u522b\uff0c\u9700\u8981\u5f3a\u5236\u8f6c\u6362\u53f3\u8fb9\u6570\u636e\u7c7b\u578b<\/li>\n\n\n\n<li>char \u4e0e short\uff0cchar \u4e0e byte \u4e4b\u95f4\u9700\u8981\u5f3a\u8f6c\uff0c\u56e0\u4e3a char \u662f\u65e0\u7b26\u53f7\u7c7b\u578b<\/li>\n<\/ul>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_16\u3001string-intern-\u4f60\u4e86\u89e3\u5417\"><a href=\"#_16\u3001string-intern-\u4f60\u4e86\u89e3\u5417\">16\u3001String. intern() \u4f60\u4e86\u89e3\u5417\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">String.intern()\u662f\u4e00\u4e2aNative(\u672c\u5730)\u65b9\u6cd5\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5982\u679c<strong>\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u5df2\u7ecf\u5305\u542b\u4e00\u4e2a\u7b49\u4e8e\u6b64String\u5bf9\u8c61\u7684\u5b57\u7b26\u4e32\uff0c\u5219\u8fd4\u56de\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u4e2d\u8fd9\u4e2a\u5b57\u7b26\u4e32\u7684\u5f15\u7528<\/strong>, <strong>\u5426\u5219\u5c06\u5f53\u524dString\u5bf9\u8c61\u7684\u5f15\u7528\u5730\u5740\uff08\u5806\u4e2d\uff09\u6dfb\u52a0\u5230\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u4e2d\u5e76\u8fd4\u56de<\/strong>\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class StringInternTest {\n    public static void main(String&#91;] args) {\n      \t\/\/ \u57fa\u672c\u6570\u636e\u7c7b\u578b\u4e4b\u95f4\u7684 ==  \u662f\u6bd4\u8f83\u503c\uff0c\u5f15\u7528\u6570\u636e\u7c7b\u578b == \u6bd4\u8f83\u7684\u662f\u5730\u5740\u503c\n      \t\/\/ 1\uff1a\u5728Java Heap\u4e2d\u521b\u5efa\u5bf9\u8c61 2\uff1a\u5728\u5b57\u7b26\u4e32\u5e38\u91cf\u6c60\u4e2d\u6dfb\u52a0 \u5c0f\u718a\u5b66Java\n        String a = new String(\"\u5c0f\u718a\u5b66Java\");\n      \t\/\/ \u8c03\u7528 intern \u65b9\u6cd5\uff0c\u56e0\u4e0a\u4e00\u6b65\u4e2d\u5df2\u7ecf\u5c06 \u5c0f\u718a\u5b66Java \u5b58\u5165\u5e38\u91cf\u6c60\u4e2d\uff0c\u8fd9\u91cc\u76f4\u63a5\u8fd4\u56de\u5e38\u91cf\u6c60 \u5c0f\u718a\u5b66Java \u7684\u5f15\u7528\u5730\u5740\n        String b = a.intern();\n      \t\/\/ a \u7684\u5730\u5740\u5728Java Heap\u4e2d \uff0c b\u7684\u5730\u5740\u5728 \u5e38\u91cf\u6c60\u4e2d \uff0c\u6240\u4ee5\u7ed3\u679c\u662fflase\n        System.out.println(a == b);\n      \t\/\/ \u56e0\u4e3a\u5e38\u91cf\u6c60\u4e2d\u5df2\u7ecf\u5305\u542b\u5c0f\u718a\u5b66Java\uff0c\u6240\u4ee5\u76f4\u63a5\u8fd4\u56de\n        String c = \"\u5c0f\u718a\u5b66Java\";\n        \/\/ b c \u7684\u5730\u5740\u4e00\u81f4\uff0c\u6240\u4ee5\u662ftrue\n        System.out.println(b == c);\n    }\n}\n\n\/\/\u7ed3\u679c\nfalse\ntrue<\/code><\/pre>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_16\u3001string\u7c7b\u4e3a\u4ec0\u4e48\u8981\u8bbe\u7f6e\u6210\u4e0d\u53ef\u53d8\"><a href=\"#_16\u3001string\u7c7b\u4e3a\u4ec0\u4e48\u8981\u8bbe\u7f6e\u6210\u4e0d\u53ef\u53d8\">16\u3001String\u7c7b\u4e3a\u4ec0\u4e48\u8981\u8bbe\u7f6e\u6210\u4e0d\u53ef\u53d8?<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<ol class=\"wp-block-list\">\n<li>\u7ebf\u7a0b\u5b89\u5168\u6027\uff1a\u4e0d\u53ef\u53d8\u7684String\u5bf9\u8c61\u53ef\u4ee5\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u5b89\u5168\u5730\u5171\u4eab\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u503c\u4e0d\u80fd\u88ab\u4fee\u6539\u3002\u8fd9\u6d88\u9664\u4e86\u5728\u5e76\u53d1\u73af\u5883\u4e2d\u8fdb\u884c\u540c\u6b65\u7684\u9700\u8981\uff0c\u63d0\u9ad8\u4e86\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/li>\n\n\n\n<li>\u7f13\u5b58\u54c8\u5e0c\u503c\uff1aString\u7c7b\u7ecf\u5e38\u88ab\u7528\u4f5c\u54c8\u5e0c\u8868\u7684\u952e\uff0c\u56e0\u6b64\u5c06String\u8bbe\u7f6e\u4e3a\u4e0d\u53ef\u53d8\u53ef\u4ee5\u786e\u4fdd\u54c8\u5e0c\u503c\u7684\u7a33\u5b9a\u6027\u3002\u5982\u679cString\u662f\u53ef\u53d8\u7684\uff0c\u90a3\u4e48\u5728\u4fee\u6539String\u7684\u503c\u540e\uff0c\u5b83\u7684\u54c8\u5e0c\u503c\u4e5f\u4f1a\u6539\u53d8\uff0c\u5bfc\u81f4\u5728\u54c8\u5e0c\u8868\u4e2d\u65e0\u6cd5\u6b63\u786e\u627e\u5230\u5bf9\u5e94\u7684\u952e\u3002<\/li>\n\n\n\n<li>\u5b89\u5168\u6027\uff1a\u4e0d\u53ef\u53d8\u7684String\u5bf9\u8c61\u53ef\u4ee5\u88ab\u5b89\u5168\u5730\u7528\u4f5c\u65b9\u6cd5\u7684\u53c2\u6570\uff0c\u56e0\u4e3a\u8c03\u7528\u65b9\u6cd5\u65f6\u65e0\u6cd5\u4fee\u6539\u5b83\u4eec\u7684\u503c\u3002\u8fd9\u6837\u53ef\u4ee5\u9632\u6b62\u6076\u610f\u4ee3\u7801\u901a\u8fc7\u4fee\u6539\u53c2\u6570\u503c\u6765\u7834\u574f\u65b9\u6cd5\u7684\u884c\u4e3a\u3002<\/li>\n\n\n\n<li>\u5b57\u7b26\u4e32\u6c60\uff1aJava\u4e2d\u7684\u5b57\u7b26\u4e32\u6c60\u662f\u4e00\u79cd\u5b57\u7b26\u4e32\u7f13\u5b58\u673a\u5236\uff0c\u5b83\u53ef\u4ee5\u91cd\u7528\u76f8\u540c\u503c\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\uff0c\u4ee5\u8282\u7701\u5185\u5b58\u3002\u7531\u4e8eString\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u53ef\u4ee5\u5c06\u76f8\u540c\u503c\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\u5b58\u50a8\u5728\u5b57\u7b26\u4e32\u6c60\u4e2d\uff0c\u4ece\u800c\u63d0\u9ad8\u5185\u5b58\u5229\u7528\u7387\u3002<\/li>\n<\/ol>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_17\u3001string\u5e38\u91cf\u6c60\u662f\u4ec0\u4e48\"><a href=\"#_17\u3001string\u5e38\u91cf\u6c60\u662f\u4ec0\u4e48\">17\u3001String\u5e38\u91cf\u6c60\u662f\u4ec0\u4e48\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">String\u5e38\u91cf\u6c60\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u5185\u5b58\u533a\u57df\uff0c\u7528\u4e8e\u5b58\u50a8\u5b57\u7b26\u4e32\u5e38\u91cf\uff0c\u907f\u514d\u91cd\u590d\u521b\u5efa\u76f8\u540c\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_18\u3001string\u5bf9\u8c61\u7684\u5185\u5b58\u5206\u914d\u662f\u653e\u5728\u6808\u4e0a\u8fd8\u662f\u5806\u4e0a\"><a href=\"#_18\u3001string\u5bf9\u8c61\u7684\u5185\u5b58\u5206\u914d\u662f\u653e\u5728\u6808\u4e0a\u8fd8\u662f\u5806\u4e0a\">18\u3001String\u5bf9\u8c61\u7684\u5185\u5b58\u5206\u914d\u662f\u653e\u5728\u6808\u4e0a\u8fd8\u662f\u5806\u4e0a\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">String\u5bf9\u8c61\u7684\u5f15\u7528\u653e\u5728\u6808\u4e0a\uff0c\u800cString\u5bf9\u8c61\u672c\u8eab\u5b58\u50a8\u5728\u5806\u4e0a\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_19\u3001\u5982\u4f55\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e92\u6362\u4e3a\u6574\u6570\u7c7b\u578b-int\"><a href=\"#_19\u3001\u5982\u4f55\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e92\u6362\u4e3a\u6574\u6570\u7c7b\u578b-int\">19\u3001\u5982\u4f55\u5c06\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e92\u6362\u4e3a\u6574\u6570\u7c7b\u578b\uff08int\uff09\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4f7f\u7528Integer.parseInt()\u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b\uff0c\u4f8b\u5982\uff1aString str = &#8220;123&#8221;; int num = Integer.parseInt(str);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u4f7f\u7528String.valueOf()\u65b9\u6cd5\u6216\u8005\u5c06\u6574\u6570\u7c7b\u578b\u4e0e\u7a7a\u5b57\u7b26\u4e32\u76f8\u52a0\uff08+&#8221; &#8220;\uff09\u6765\u5c06\u6574\u6570\u7c7b\u578b\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\uff0c\u4f8b\u5982\uff1aint num = 123; String str = String.valueOf(num); \u6216\u8005 String str = num + &#8220;&#8221;;<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_20\u3001\u5305\u88c5\u7c7b\u548c\u57fa\u672c\u7c7b\u578b\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\u6709\u4ec0\u4e48\u533a\u522b\"><a href=\"#_20\u3001\u5305\u88c5\u7c7b\u548c\u57fa\u672c\u7c7b\u578b\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\u6709\u4ec0\u4e48\u533a\u522b\">20\u3001\u5305\u88c5\u7c7b\u548c\u57fa\u672c\u7c7b\u578b\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\u7684\u4f4d\u7f6e\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u57fa\u672c\u7c7b\u578b\u7684\u53d8\u91cf\u5b58\u50a8\u5728\u6808\u5185\u5b58\u4e2d\uff0c\u800c\u5305\u88c5\u7c7b\u5bf9\u8c61\u5b58\u50a8\u5728\u5806\u5185\u5b58\u4e2d<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_21\u3001\u5305\u88c5\u7c7b\u7684\u7f13\u5b58\u662f\u4ec0\u4e48\u610f\u601d\"><a href=\"#_21\u3001\u5305\u88c5\u7c7b\u7684\u7f13\u5b58\u662f\u4ec0\u4e48\u610f\u601d\">21\u3001\u5305\u88c5\u7c7b\u7684\u7f13\u5b58\u662f\u4ec0\u4e48\u610f\u601d\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5728\u8303\u56f4\u8f83\u5c0f\u7684\u6570\u503c\u8303\u56f4\u4e2d\uff0cJava\u7684\u5305\u88c5\u7c7b\u4f1a\u4f7f\u7528\u7f13\u5b58\u6765\u63d0\u9ad8\u6027\u80fd\uff0c\u4f8b\u5982Integer\u7c7b\u4f1a\u7f13\u5b58-128\u81f3127\u4e4b\u95f4\u7684\u6574\u6570\u5bf9\u8c61\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_22\u3001java\u4e2d\u65e5\u671f\u548c\u65f6\u95f4\u7684\u5904\u7406\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u662f\u5426\u5b89\u5168\"><a href=\"#_22\u3001java\u4e2d\u65e5\u671f\u548c\u65f6\u95f4\u7684\u5904\u7406\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u662f\u5426\u5b89\u5168\">22\u3001Java\u4e2d\u65e5\u671f\u548c\u65f6\u95f4\u7684\u5904\u7406\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u662f\u5426\u5b89\u5168\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">java.util.Date\u7c7b\u548cjava.util.Calendar\u7c7b\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u662f\u4e0d\u5b89\u5168\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528java.time\u5305\u4e2d\u7684\u7c7b\u6765\u5b9e\u73b0\u7ebf\u7a0b\u5b89\u5168\u7684\u65e5\u671f\u548c\u65f6\u95f4\u5904\u7406<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"_23\u3001java-8\u5f15\u5165\u4e86\u65b0\u7684\u65e5\u671f\u548c\u65f6\u95f4api\u7684\u4e3b\u8981\u76ee\u7684\u662f\u4ec0\u4e48\"><a href=\"#_23\u3001java-8\u5f15\u5165\u4e86\u65b0\u7684\u65e5\u671f\u548c\u65f6\u95f4api\u7684\u4e3b\u8981\u76ee\u7684\u662f\u4ec0\u4e48\">23\u3001Java 8\u5f15\u5165\u4e86\u65b0\u7684\u65e5\u671f\u548c\u65f6\u95f4API\u7684\u4e3b\u8981\u76ee\u7684\u662f\u4ec0\u4e48\uff1f<\/a><\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Java 8\u5f15\u5165\u4e86\u65b0\u7684\u65e5\u671f\u548c\u65f6\u95f4API\uff08<code>java.time<\/code>\u5305\uff09\u7684\u4e3b\u8981\u76ee\u7684\u662f\u6539\u8fdbJava\u4e2d\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u7684\u80fd\u529b\u3002\u65e7\u7684<code>java.util.Date<\/code>\u548c<code>java.util.Calendar<\/code>\u7c7b\u5728\u8bbe\u8ba1\u4e0a\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff0c\u6bd4\u5982\u53ef\u53d8\u6027\u3001\u7ebf\u7a0b\u5b89\u5168\u6027\u548c\u6613\u7528\u6027\u7b49\u65b9\u9762\u7684\u6311\u6218\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b0\u7684\u65e5\u671f\u548c\u65f6\u95f4API\u89e3\u51b3\u4e86\u8fd9\u4e9b\u95ee\u9898\uff0c\u5e76\u63d0\u4f9b\u4e86\u66f4\u597d\u7684API\u8bbe\u8ba1\u548c\u529f\u80fd\u3002\u5b83\u7684\u4e3b\u8981\u76ee\u6807\u5305\u62ec\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0d\u53ef\u53d8\u6027\uff1a\u65b0\u7684API\u4e2d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u7c7b\u90fd\u662f\u4e0d\u53ef\u53d8\u7684\uff0c\u8fd9\u610f\u5473\u7740\u4e00\u65e6\u521b\u5efa\uff0c\u5b83\u4eec\u7684\u503c\u5c31\u4e0d\u4f1a\u6539\u53d8\u3002\u8fd9\u6709\u52a9\u4e8e\u907f\u514d\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u51fa\u73b0\u5e76\u53d1\u95ee\u9898\uff0c\u5e76\u4e14\u66f4\u7b26\u5408\u65e5\u671f\u548c\u65f6\u95f4\u7684\u672c\u8d28\u7279\u6027\u3002<\/li>\n\n\n\n<li>\u7ebf\u7a0b\u5b89\u5168\u6027\uff1a\u65b0\u7684API\u4e2d\u7684\u65e5\u671f\u548c\u65f6\u95f4\u7c7b\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\uff0c\u53ef\u4ee5\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u5b89\u5168\u4f7f\u7528\uff0c\u800c\u65e0\u9700\u989d\u5916\u7684\u540c\u6b65\u63aa\u65bd\u3002<\/li>\n\n\n\n<li>\u6613\u7528\u6027\uff1a\u65b0\u7684API\u63d0\u4f9b\u4e86\u4e00\u7ec4\u6e05\u6670\u3001\u4e00\u81f4\u4e14\u6613\u4e8e\u4f7f\u7528\u7684\u65b9\u6cd5\u6765\u5904\u7406\u65e5\u671f\u548c\u65f6\u95f4\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\uff0c\u5982\u65e5\u671f\u8ba1\u7b97\u3001\u683c\u5f0f\u5316\u3001\u89e3\u6790\u3001\u65f6\u533a\u5904\u7406\u7b49\uff0c\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u80fd\u591f\u66f4\u8f7b\u677e\u5730\u5904\u7406\u5404\u79cd\u65e5\u671f\u548c\u65f6\u95f4\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li>\u6269\u5c55\u6027\uff1a\u65b0\u7684API\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6269\u5c55\u70b9\uff0c\u4f7f\u5f97\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u81ea\u5b9a\u4e49\u548c\u6269\u5c55\u65e5\u671f\u548c\u65f6\u95f4\u7684\u5904\u7406\u80fd\u529b\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\u3002<\/li>\n<\/ol>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001Java \u7684\u57fa\u672c\u6570\u636e\u7c7b\u578b\u90fd\u6709\u54ea\u4e9b\u5404\u5360\u51e0\u4e2a\u5b57\u8282\uff1f 2\u3001String \u662f\u6700\u57fa\u672c\u7684\u6570\u636e\u7c7b\u578b\u5417\uff1f \u4e0d\u662f\uff0cStrin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":234,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[103,104],"tags":[],"class_list":["post-1384","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"_links":{"self":[{"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/posts\/1384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1384"}],"version-history":[{"count":2,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/posts\/1384\/revisions"}],"predecessor-version":[{"id":1448,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/posts\/1384\/revisions\/1448"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/media\/234"}],"wp:attachment":[{"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zero-zl.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}