![]() While the values can also be initialized as other data structures like ArrayList, Linked List, etc, the keys can't. Factors affecting the performance of HashMap - Initial Capacity, Load Factor, ThresholdĪs told above, it is a type of Data Structure that is used to store data in the form of key and value pairs where both key and value are initialized using object/wrapper classes of the primitive data types like Integer, Boolean, String - which is already a wrapper class. ![]() Basic Operations of HashMap - Adding Elements, Changing Elements, Removing Elements, Iterating over HashMap.Now that we have a basic understanding of what a HashMap is and why was it introduced, let's see how HashMap is different from others. The price we pay for using the HashMap is that it increases the amount of auxiliary space which will be equal to the number of items stored. HashMap takes a constant time to do every operation like add, delete, replace, etc whereas other data structures take the time equal to the amount of data stored in it - O(n) and O(log n) if the data is sorted. One might ask, we already have so many data structures like Arrays, Linked List, etc, to store data, then what is the need to introduce a new one? The answer is simple, though the HashMap is used for the same thing as other data structures, it takes less time than them. It means that every key is mapped to exactly one value and that we can use it to retrieve its corresponding value from the map. It stores data in the form of Key and Value pairs where the key is a unique identifier used to associate each value on the Map. HashMap in Java is a part of Java Collections Frameworks since Java 1.2 and provides the basic implementation of the Map interface in Java.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |