{"id":545,"date":"2009-02-18T13:40:52","date_gmt":"2009-02-18T18:40:52","guid":{"rendered":"http:\/\/jianmingli.com\/wp\/?p=545"},"modified":"2009-02-18T13:42:23","modified_gmt":"2009-02-18T18:42:23","slug":"java-collections","status":"publish","type":"post","link":"https:\/\/jianmingli.com\/wp\/?p=545","title":{"rendered":"Java Collections"},"content":{"rendered":"<p><strong>Sets, Lists, HashMaps<\/strong><\/p>\n<p><strong>Sets<\/strong><\/p>\n<pre lang=\"java\">\r\nSet set = new HashSet(Arrays.asList(elements));\r\n\r\npublic TreeSet(Comparator comp)\r\n\r\nheadSet(Object to)\r\n\r\ntailSet(Object from)\r\n\r\nsubSet(Object from, Object to)\r\n<\/pre>\n<p><strong>ArrayList,LinkedList<\/strong><br \/>\n* can ONLY find index from either beginning and end<br \/>\n* ListIterator<\/p>\n<p><strong>HashMap<\/strong><br \/>\nMap.Entry<\/p>\n<pre lang=\"java\">\r\nProperties p = System.getProperties();\r\nIterator i = p.entrySet().iterator();\r\nwhile(i.hasNext){\r\n Map.Entry e = (MapEntry)i.next();\r\n e.getKey();\r\n e.getValue();\r\n}\r\npublic Set keySet();\r\npublic Collection values();\r\npublic Set entrySet();\r\n<\/pre>\n<p><strong>Vector<\/strong><br \/>\n-Use linkedList to add element in the middle<br \/>\n-Vector v =<br \/>\nnew Vector(Arrays.asList(array));<br \/>\n-vector.removeAll(Collection c);<br \/>\n-vector.retainAll(Collection c);<br \/>\n-vector.containsAll(Collection c);<br \/>\n-Sort Vector:<br \/>\n Vector v1 = &#8230;;<br \/>\n Vector v2 = (Vector)v1.clone();<br \/>\n Collections.sort(v2);<br \/>\n-toArray: the smart way<br \/>\n Vector v = &#8230;<br \/>\n String[] array = new String[v.size()];<br \/>\n v.copyInto(array);<br \/>\n-Stack class inherits from Vector<\/p>\n<p>\u2022java.lang.ref<br \/>\nstrong soft weak phantom<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sets, Lists, HashMaps Sets Set set = new HashSet(Arrays.asList(elements)); public TreeSet(Comparator comp) headSet(Object to) tailSet(Object from) subSet(Object from, Object to) ArrayList,LinkedList * can ONLY find index from either beginning and end * ListIterator HashMap Map.Entry Properties p = System.getProperties(); Iterator &hellip; <a href=\"https:\/\/jianmingli.com\/wp\/?p=545\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14],"tags":[],"class_list":["post-545","post","type-post","status-publish","format-standard","hentry","category-java"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8cRUO-8N","_links":{"self":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/545","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=545"}],"version-history":[{"count":2,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":547,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/545\/revisions\/547"}],"wp:attachment":[{"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jianmingli.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}