Java

Topic: Collection Framework

What is performance of Map interface implementations

HashtableAn instance of Hashtable has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. Note that the hash table is open: in the case of a "hash collision", a single bucket stores multiple entries, which must be searched sequentially. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. The initial capacity and load factor parameters are merely hints to the implementation. The exact details as to when and whether the rehash method is invoked are implementation-dependent.HashMapThis implementation provides constant-time [ Big O Notation is O(1) ] performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets. Iteration over collection views requires time proportional to the "capacity" of the HashMap instance (the number of buckets) plus its size (the number of key-value mappings). Thus, it's very important not to set the initial capacity too high (or the load factor too low) if iteration performance is important.TreeMapThe TreeMap implementation provides guaranteed log(n) [ Big O Notation is O(log N) ] time cost for the containsKey, get, put and remove operations.LinkedHashMapA linked hash map has two parameters that affect its performance: initial capacity and load factor. They are defined precisely as for HashMap. Note, however, that the penalty for choosing an excessively high value for initial capacity is less severe for this class than for HashMap, as iteration times for this class are unaffected by capacity.

Browse random answers:

What are the goals of collections framework?
Explain the contents of collection framework? 
Explain interfaces of collectonframework?
Explain the collection classes?
Explain algorithms in collection framework?
How to use an Iterator ?
How to use an Comparator ?
What is the difference between java.util.Iterator and java.util.ListIterator?
What is HashMap and Map? 
Difference between HashMap and HashTable? Compare Hashtable vs HashMap?
What does synchronized means in Hashtable context?
What is fail-fast property?
Why doesn't Collection extend Cloneable and Serializable?
How can we make Hashmap synchronized?
Where will you use Hashtable and where will you use HashMap?
Difference between Vector and ArrayList? What is the Vector class? 
What is the Difference between Enumeration and Iterator interface?
Why Java Vector class is considered obsolete or unofficially deprecated? or Why should I always use ArrayList over Vector?
What is an enumeration?
What is the difference between Enumeration and Iterator?
Where will you use Vector and where will you use ArrayList?
What is the importance of hashCode() and equals() methods? How they are used in Java?
What is the difference between Sorting performance of Arrays.sort() vs Collections.sort() ? Which one is faster? Which one to use and when?
What is java.util.concurrent BlockingQueue? How it can be used?
Set & List interface extend Collection, so Why doesn't Map interface extend Collection?
Which implementation of the List interface provides for the fastest insertion of a new element into the middle of the list? 
What is the difference between ArrayList and LinkedList? (ArrayList vs LinkedList.) 
Where will you use ArrayList and Where will you use LinkedList? Or Which one to use when (ArrayList / LinkedList).
What is performance of Map interface implementations
What is Performance of Set interface implementations
What is Performance of List interface implementations