Java Collection Knowledge Collation

Source: Internet
Author: User

    1. Java Collection Class diagram

    1. The difference between HashMap and Hashtable
HashMap HashTable
How to Inherit
Extends Abstractmap implements Map
Extends Dictionary implements Map
Thread Safety Is Whether
Efficiency relative ratio High Low
Allow null keys and values Is Whether
Determine which methods are included Containsvalue and ContainsKey Contains

Hash array Default Size

11,

16,

Hash array Increment mode

Old*2+1

2 Increase in Index

    1. The traversal of the list
1list<string> list =NewArraylist<string>();2 3String prestring = "AA";4          for(intj = 0; J < 100000000; J + +) {5 List.add (prestring);6         }7 8         //Method 1 (fastest, list specific)9          for(inti = 0, Len = list.size (); i < Len; i++) {Ten List.get (i); One         } A  -         //Method 2 (for each-is the most time consuming) -          for(String tmp:list) { the         } -  -         //Method 3 (as with method 2,4, applies to all classes that implement the Iterable interface, which are common: queue,set,collection,list) -Iterator<string> iter =list.iterator (); +          while(Iter.hasnext ()) { -String str =Iter.next (); +         } A      at         //Method 4 -          for(Iterator<string> it2 =list.iterator (); It2.hasnext ();) { -String str =It2.next (); -}

Traversal of 2.map

1Hashmap<integer, string> map =NewHashmap<>();2String v = "value";3          for(inti=0;i<10000000;i++){4 Map.put (i, v);5         }6         7         //Method 1,8Iterator<map.entry<integer, string>> it1=Map.entryset (). iterator ();9          while(It1.hasnext ()) {TenMap.entry<integer, string> Entry =It1.next (); One             intKey =Entry.getkey (); AString value =Entry.getvalue (); -         } -      the         //Method 2 Gets the iterator for the key collection of map, which is 7 times times the time of Method 1.  -Iterator<integer> it2 =Map.keyset (). iterator (); -          while(It2.hasnext ()) { -             intKey =It2.next (); +String value =Map.get (key); -         } +     

Set and map traverse in a similar way, it is not here to wordy.

Java Collection Knowledge Collation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.