WebDriver Java Concepts - HashMaps
So a lot of automation engineers I know have started to venture into the world of Selenium WebDriver. Looking at this I will now start a series of posts that will be tagged as "WebDriver Java Concepts". The intention will be to add concepts of Java and WebDriver that a newbie should learn.
To start with one of the most popular concepts that is used in Selenium frameworks:
HashMap - Hashmaps in simple terms are nothing but key value pairs just like the object dictionary that we have in QTP. A more technical definition would be that "The HashMap class uses a hash table to implement the Map interface. This allows the execution time of basic operations, such as get( ) and put( ), to remain constant even for large sets."
Points to ponder:
- The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.
- The HashMap class supports four constructors.
- The first form constructs a default hash map: HashMap( )
- The second form initializes the hash map by using the elements of m: HashMap(Map m)
- The third form initializes the capacity of the hash map to capacity: HashMap(int capacity)
- The fourth form initializes both the capacity and fill ratio of the hash map by using its arguments: HashMap(int capacity, float fillRatio)
- An instance of HashMap 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. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed
- You should note that a hash map does not guarantee the order of its elements. Therefore, the order in which elements are added to a hash map is not necessarily the order in which they are read by an iterator.