{"id":818,"date":"2010-10-01T11:57:18","date_gmt":"2010-10-01T11:57:18","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=818"},"modified":"2010-10-01T11:57:18","modified_gmt":"2010-10-01T11:57:18","slug":"list%e3%80%81set%e3%80%81%e6%95%b0%e7%bb%84%e4%b9%8b%e9%97%b4%e7%9a%84%e8%bd%ac%e6%8d%a2","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/10\/01\/list%e3%80%81set%e3%80%81%e6%95%b0%e7%bb%84%e4%b9%8b%e9%97%b4%e7%9a%84%e8%bd%ac%e6%8d%a2\/","title":{"rendered":"List\u3001Set\u3001\u6570\u7ec4\u4e4b\u95f4\u7684\u8f6c\u6362"},"content":{"rendered":"<p>\u4f7f\u7528Apache Jakarta Commons Collections\uff1a<\/p>\n<div>\n<ol>\n<li>import org.apache.commons.collections.CollectionUtils; ??<\/li>\n<li>??<\/li>\n<li>String[] strArray = {&#8220;aaa&#8221;, &#8220;bbb&#8221;, &#8220;ccc&#8221;}; ??<\/li>\n<li>List strList = new ArrayList(); ??<\/li>\n<li>Set strSet = new HashSet(); ??<\/li>\n<li>CollectionUtils.addAll(strList, strArray); ??<\/li>\n<li>CollectionUtils.addAll(strSet, strArray);??<\/li>\n<\/ol>\n<\/div>\n<p>CollectionUtils.addAll()\u65b9\u6cd5\u7684\u5b9e\u73b0\u5f88\u7b80\u5355\uff0c\u53ea\u662f\u5faa\u73af\u4f7f\u7528\u4e86Collection\u7684add()\u65b9\u6cd5\u800c\u5df2\u3002<\/p>\n<p>\u5982\u679c\u53ea\u662f\u60f3\u5c06\u6570\u7ec4\u8f6c\u6362\u6210List\uff0c\u53ef\u4ee5\u7528JDK\u4e2d\u7684java.util.Arrays\u7c7b\uff1a<\/p>\n<div>\n<ol>\n<li>import java.util.Arrays; ??<\/li>\n<li>??<\/li>\n<li>String[] strArray = {&#8220;aaa&#8221;, &#8220;bbb&#8221;, &#8220;ccc&#8221;}; ??<\/li>\n<li>List strList = Arrays.asList(strArray);??<\/li>\n<\/ol>\n<\/div>\n<p>\u4e0d\u8fc7Arrays.asList()\u65b9\u6cd5\u8fd4\u56de\u7684List\u4e0d\u80fdadd\u5bf9\u8c61\uff0c\u56e0\u4e3a\u8be5\u65b9\u6cd5\u7684\u5b9e\u73b0\u662f\u4f7f\u7528\u53c2\u6570\u5f15\u7528\u7684\u6570\u7ec4\u7684\u5927\u5c0f\u6765new\u7684\u4e00\u4e2aArrayList\u3002<\/p>\n<p>\u2605 <strong>Collection\u8f6c\u6570\u7ec4<\/strong><\/p>\n<p>\u76f4\u63a5\u4f7f\u7528Collection\u7684toArray()\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u6709\u4e24\u4e2a\u91cd\u8f7d\u7248\u672c\uff1a<\/p>\n<div>\n<ol>\n<li>Object[] toArray(); ??<\/li>\n<li>??<\/li>\n<li>T[] toArray(T[] a);??<\/li>\n<\/ol>\n<\/div>\n<p>?<\/p>\n<p>\u2605 <strong>Map\u8f6cCollection<\/strong><\/p>\n<p>\u76f4\u63a5\u4f7f\u7528Map\u7684values()\u65b9\u6cd5\u3002<\/p>\n<p>\u2605 <strong>List\u548cSet\u8f6c\u6362<\/strong><\/p>\n<div>\n<p>List list = new ArrayList(new Hashset());\/\/ Fixed-size list<br \/>\nList list = Arrays.asList(array);\/\/ Growable<br \/>\nlist list = new LinkedList(Arrays.asList(array));\/\/ Duplicate elements are discarded<br \/>\nSet set = new HashSet(Arrays.asList(array));<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528Apache Jakarta Commons Collections\uff1a import org.apache [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-818","post","type-post","status-publish","format-standard","hentry","category-java"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=818"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/818\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}