COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Values
|
|
Keys and values
|
|
Keys
|
|
Strings
|
Detailed explanation-1: -HashMap stores entries into multiple singly linked lists, called buckets or bins. Default number of bins is 16 and it’s always power of 2. HashMap uses hashCode() and equals() methods on keys for get and put operations. So HashMap key object should provide good implementation of these methods.
Detailed explanation-2: -HashMap is a data structure that uses a hash function to map identifying values, known as keys, to their associated values. It contains “key-value” pairs and allows retrieving value by key.
Detailed explanation-3: -The basic idea of HashMap is this: A HashMap is really an array of special objects that hold both Key and Value.
Detailed explanation-4: -No, the order is not preserved in case of HashMap (if you want sorted implementation.) In case you want keys to be sorted, you can use TreeMap.
Detailed explanation-5: -HashMap uses a linked list in case of collision and objects will be stored in the next node of the linked list. Also, HashMap stores both key and value tuples in every node of the linked list in the form of Map. Entry object.