{"id":36973,"date":"2024-11-26T14:23:42","date_gmt":"2024-11-26T06:23:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/36973\/"},"modified":"2024-11-26T14:23:42","modified_gmt":"2024-11-26T06:23:42","slug":"java%e6%80%8e%e4%b9%88%e5%ad%98string%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/36973\/","title":{"rendered":"java\u600e\u4e48\u5b58string\u6570\u7ec4"},"content":{"rendered":"<blockquote><p>\n  java \u4e2d\u50a8\u5b58 string \u6570\u7ec4\u6709\u4e24\u79cd\u5e38\u7528\u65b9\u6cd5\uff1astring \u6570\u7ec4\uff1a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\uff0c\u4f7f\u7528 [] \u58f0\u660e\u3002arraylist\uff1a\u52a8\u6001\u6570\u7ec4\uff0c\u4f7f\u7528 \u58f0\u660e\uff0c\u53ef\u4ee5\u4f7f\u7528 add() \u548c remove() \u65b9\u6cd5\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/12\/2024111222341193159.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u5b58string\u6570\u7ec4\u63d2\u56fe\" alt=\"java\u600e\u4e48\u5b58string\u6570\u7ec4\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u4e2d\u50a8\u5b58 String \u6570\u7ec4\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>Java \u4e2d\u50a8\u5b58 String \u6570\u7ec4\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u6700\u5e38\u7528\u7684\u4e24\u79cd\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528 String \u6570\u7ec4<\/strong><\/p>\n<p>\u8fd9\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u53ea\u9700\u58f0\u660e\u4e00\u4e2a String \u7c7b\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\u5373\u53ef\u3002\u4f8b\u5982\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>String[] names = {\"Alice\", \"Bob\", \"Carol\", \"Dave\"};<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 ArrayList<\/strong><\/p>\n<p>ArrayList \u662f\u4e00\u4e2a\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u968f\u7740\u9700\u8981\u81ea\u52a8\u589e\u957f\u3002\u8981\u521b\u5efa ArrayList\uff0c\u8bf7\u5148\u5bfc\u5165 java.util.ArrayList \u7c7b\uff0c\u7136\u540e\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u5b9e\u4f8b\uff1a<\/p>\n<pre>import java.util.ArrayList;\n\nArrayList&lt;String&gt; names = new ArrayList&lt;&gt;();\n\n\/\/ \u6dfb\u52a0\u5143\u7d20\nnames.add(\"Alice\");\nnames.add(\"Bob\");\nnames.add(\"Carol\");\nnames.add(\"Dave\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e24\u79cd\u65b9\u6cd5\u7684\u6bd4\u8f83<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u7279\u5f81<\/th>\n<th>String \u6570\u7ec4<\/th>\n<th>ArrayList<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u7c7b\u578b<\/td>\n<td>\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4<\/td>\n<td>\u52a8\u6001\u6570\u7ec4<\/td>\n<\/tr>\n<tr>\n<td>\u58f0\u660e<\/td>\n<td>\u4f7f\u7528 [] \u58f0\u660e<\/td>\n<td>\u4f7f\u7528 \u58f0\u660e<\/td>\n<\/tr>\n<tr>\n<td>\u8bbf\u95ee\u5143\u7d20<\/td>\n<td>\u4f7f\u7528\u4e0b\u6807\u8fd0\u7b97\u7b26<\/td>\n<td>\u4f7f\u7528 get() \u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>\u6dfb\u52a0\u5143\u7d20<\/td>\n<td>\u65e0\u6cd5\u5728\u58f0\u660e\u540e\u6dfb\u52a0\u5143\u7d20<\/td>\n<td>\u53ef\u4ee5\u4f7f\u7528 add() \u65b9\u6cd5\u6dfb\u52a0\u5143\u7d20<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u5143\u7d20<\/td>\n<td>\u65e0\u6cd5\u5220\u9664\u5143\u7d20<\/td>\n<td>\u53ef\u4ee5\u4f7f\u7528 remove() \u65b9\u6cd5\u5220\u9664\u5143\u7d20<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5<\/strong><\/p>\n<p>\u5982\u679c\u77e5\u9053\u6570\u7ec4\u7684\u5927\u5c0f\u4e0d\u4f1a\u6539\u53d8\uff0c\u5219\u4f7f\u7528 String \u6570\u7ec4\u66f4\u52a0\u9ad8\u6548\u3002\u7136\u800c\uff0c\u5982\u679c\u9700\u8981\u4e00\u4e2a\u53ef\u4ee5\u968f\u7740\u9700\u8981\u800c\u589e\u957f\u7684\u52a8\u6001\u6570\u7ec4\uff0c\u5219 ArrayList \u662f\u66f4\u597d\u7684\u9009\u62e9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u5b58string\u6570\u7ec4\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>java \u4e2d\u50a8\u5b58 string \u6570\u7ec4\u6709\u4e24\u79cd\u5e38\u7528\u65b9\u6cd5\uff1astring \u6570\u7ec4\uff1a\u56fa\u5b9a\u5927\u5c0f\u7684\u6570\u7ec4\uff0c\u4f7f\u7528 [] \u58f0\u660e\u3002arraylist\uff1a\u52a8\u6001\u6570\u7ec4\uff0c\u4f7f\u7528 \u58f0\u660e\uff0c\u53ef\u4ee5\u4f7f\u7528 add() \u548c remove() \u65b9\u6cd5\u6dfb\u52a0\u548c\u5220\u9664\u5143\u7d20\u3002 Java \u4e2d\u50a8\u5b58 String \u6570\u7ec4\u7684\u65b9\u6cd5 Java \u4e2d\u50a8\u5b58 String \u6570\u7ec4\u6709\u51e0\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u6700\u5e38\u7528\u7684\u4e24\u79cd\uff1a 1. \u4f7f\u7528 String \u6570\u7ec4 \u8fd9\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u53ea\u9700\u58f0\u660e\u4e00\u4e2a String \u7c7b\u578b\u7684\u4e00\u7ef4\u6570\u7ec4\u5373\u53ef\u3002\u4f8b\u5982\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b String[] names = {&#8220;Alice&#8221;, &#8220;Bob&#8221;, &#8220;Carol&#8221;, &#8220;Dave&#8221;}; \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 ArrayList ArrayList \u662f\u4e00\u4e2a\u52a8\u6001\u6570\u7ec4\uff0c\u53ef\u4ee5\u968f\u7740\u9700\u8981\u81ea\u52a8\u589e\u957f\u3002\u8981\u521b\u5efa ArrayList\uff0c\u8bf7\u5148\u5bfc\u5165 java.util.ArrayList \u7c7b\uff0c\u7136\u540e\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u5b9e\u4f8b\uff1a import java.util.ArrayList; ArrayList&lt;String&gt; names = new ArrayList&lt;&gt;(); \/\/ \u6dfb\u52a0\u5143\u7d20 names.add(&#8220;Alice&#8221;); names.add(&#8220;Bob&#8221;); [&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-36973","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36973","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=36973"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/36973\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=36973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=36973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=36973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}