OK we're not done with the collection hierarchy. 2
Now it's time to look at the map hierarchy which is a second inheritance tree in the collections framework 3
. 4
Let's begin by looking at the map interface which is the root of the map hierarchy. 5
We pretty much discuss all of these points during our discussion on hash table. 6
But let's quickly glanced through them once again not a map store key value pairs and they're useful 7
for Fras lookups. 8
Biccies IMAP implementation like a hash map is also referred to as an associate the way maps can not 9
have duplicate IIS but duplicate values are fine on each key maps to at most one value not some map 10
implementations allow only one Halki while others do not allow any Nalco at all. 11
Similarly null values may be allowed or they may be prohibited. 12
One of the like in the case of collection map also comes with a skeletal implementation abstract map 13
. 14
So limitations like hash map extend this particular class just know that it's not just map collection 15
interfaces which come with skeletally implementations even list certain new interfaces. 16
Also combat's little implementations under also appropriately named as abstract list abstract set an 17
abstract Q On all three of them. 18
Extend that abstract collection. 19
And here is the declaration of map interface similar to collection and office. 20
This interface also has methods which are classified and do basic operations on bulk operations collection 21
interface. 22
Also how are the operations and we don't how anything of that sort in the map interface. 23
But map has something called collection view operations and B-ble will soon we'll get them look at Unlike 24
collection map interface does not extend the interface but the elements can still be detected and we 25
will see how that can be done. 26
And here are the methods which follow the basic operations. 27
Not that here the genetics notation involves the letters K and the V K would stand for key while before 28
value but don't bother about them as we still did not discuss genetics. 29
But we know that Canvey can represent anything. 30
Right. 31
So that's what genetics is about. 32
And that anything will be specified at the object creation. 33
That is when we are creating an instance of a particular map implementation on the first method. 34
Here is the put method. 35
It simply asks that given key and value pair into the map. 36
If there is already a mapping with the same key then the value in that mapping will be overwritten with 37
the new value. 38
We already discussed it when covering hash table. 39
Also the old value will be returned by the matter. 40
So that's the reason the written type for this method is V where we would be the all value. 41
But if there was no mapping with that key then the new mapping will be inserted and the null value will 42
be returned. 43
But if the map implementation allows it not you. 44
And there is a matching key with a null value then the null value would be written. 45
So in this case we cannot tell whether the null value that was written was due to inserting an entirely 46
new mapping or if it was due to overwriting an existing mapping which had a null value. 47
But to distinguish these two cases we can invoke the Kandinsky method which returns a true if the input 48
key is present in the map. 49
Next is the get method. 50
Undertreatment the value corresponding by a given key. 51
If there is no mapping with that key then a null is written the moment that would remove the mapping 52
for a key under a corresponding value attribute in a null. 53
If the mapping with a matching key was not for it it is because contains key convinced volume that would 54
return true if the map contains the specified value size would read and the size of the map is empty 55
. 56
Would return true if the size of the map is zero which means that it is empty. 57
And here are the bulk operations. 58
Put all method what are all the mappings from the input map into the current map. 59
So it is similar to the idle method in the collection interface and cleared matter. 60
Simply remove all the mappings from the map. 61
Even the collection interface had an identical method and he had a collection view operations you would 62
use the first method. 63
He said if you want to view all the keys present in the map. 64
So this method would it an asset. 65
If you want to remove one element from the ribbon set you can invoke the return method on the return 66
set and then you can invoke the remote method on the return to do it. 67
Alternatively we can also use set methods like Rimmel. 68
Remove all retain all and clear. 69
However you cannot work either add or are all methods and you will get an unsupported operation exception 70
. 71
If you invoke these matters not that the return set is bad but the origin Alima. 72
So any changes made in the returns it will be reflected in the original map and vice versa. 73
Next is a values motard and it will return a collection view of all the values in the map on all the 74
properties we just discussed. 75
For the keyset method will also apply for this method. 76
Note that in case of keyset a set was written whereas in this case a collection is being written. 77
And can you guess the reason for that. 78
It is just because Keys are unique and so a set is returned the rest values can contain duplicate and 79
hence a collection is written. 80
Not a third method and Chrisette is an interesting method and it can be used for creating them up. 81
It returns a set view of all the mappings in the map on each mapping is an instance of this interface 82
called entry which is a nested interface within the map interface so it is not just a process but we 83
can also how interfaces as an interface is a nice thing about such a nested interface is that it improves 84
the readability. 85
No how did been a separate individual interface served as a separate file. 86
Then it would unnecessarily pollute the namespace even though it is used only by MAP implementations 87
. 88
So someone looking at this package might do. 89
HUME That angry interface is very widely used but now in this case since it is part of the map interface 90
one would assume that it has something to do with only maps. 91
Now here each instance of entry corresponds to a mapping in MAP unsoiled stores both he as well as value 92
on hence pro-white my thoughts like get it and get value. 93
So any derating them up these methods can be invoked. 94
There is also the set value method which can be used to update the value in a particular mapping. 95
Anyway we were tested. 96
In the next question. 97
When we look at hash map just know that like the other two collection will return the set that is returned 98
. 99
But this particular method is backed by the original map and so all properties with regards to making 100
any changes will also apply here. 101
Finally just note that you should be very careful if the keys you use are immutable. 102
You would want to use keys which are immutable like the strings. 103
The reason is if you start a mutable object esky and then later you change the state of the object. 104
Then when you search for that same key the map method and a null value for instance if the map is a 105
hash map then the hash function might give a different index value. 106
That is the bucket number after the object stood was changed. 107
That is the hash function so logic is dependent on the objects state. 108
Even if it was the same bucket number the subsequent equals method might see that no matching mapping 109
was found in the corresponding linked list. 110
Anyway Robert does this out later in the demo. 111
So let's not worry if it's not really clear to you. 112
So that's up with the map interface in the next lesson. 113
They will look at hash map and maybe just all the matters that we have seen in this lesson. 114
So just state your own and it's going to be an interesting them. 115
Thank you