HashMap Methods and its use Flashcards
- What is the difference between remove (key) and remove(key, value ) pair?
- What is the use of put, put all, remove(Key) and remove(Key value) , get(key), clear(), size(), isEmpty()., replace, replaceall().
- Does collection have length or Size?
- If we give remove (key) we will get the value in output.
If we give remove(Key, value) we will get true . - 1Put() - Is used to add all the (Key, value) pair,
after that in syso we can pass the reference object (hm) and print all the values
2.Put all() - it a void return type it won’t return anything , we need to create a new object and pass the parent class Map object inside this pull and print the statement using second object which is created.
3.remove (key) will remove and give the value ./if we give outside it will remove and won’t give anything if we give in print statement it will give the value in output
remove(key , value ) will print true or false. //if we give outside it will remove(key value) and won’t give true or false it will just remove if we give in print statement it will give the value in output
4.get(key) - if we removed already the get key value which we gonna use not it will print output as null.
getKey() returns a keyset() method of set.
either it will print the “ value” of the key
5.Clear is used to clear() all the keys and values .
6.size() will check and give whether 3 or 4 according to ur inputs
7.Isempty() will check whether it is Empty or not.
- Collections have only size , length is used for Strings and Arrays.
1.What is mean by Entry?
2. Does Key value-> have duplicates?
3. why in hashmap key says as keyset()?
4.Can we say values as List in hahsmap?
5. Is map is a separate entity?
6.collection view of map and its methods?
1.Key + value = Entry, collection of entries is called Map
2.No Key value -> entry don’t have duplicate . Entry should be unique.
3.Because set have unique value so here key also have unique value so we call it as keyset()
4. yes we can say it , but it can also be list when it don’t have duplicate values. it is said as value list , value set.
5. yes map is a separate entity, collection of view : Map
6. Set keyset(), collectionvalues(), Set entry set().
- What are all the Interfaces you know?
- What are the methods entry have?
- What is map.entry?
- Collection, List, Set comparator, comparable, navigableset, sorted set, navigablemap,
- getkey(), get value() return type for this is Object
- Without map there is no entry so we use Map.entry
- What is the use of entryset()
2.What is the use of collectionvalues
3..What is the use of keyset
- entry set will give all the entries in [] only if we give
Set sc = reference name(hm) .entrySet(). if we just give
hm.entySet() and in print statment to hm it will print in curly braces - Same as above Collections cc = hm.values();
it will give only values of the entries. - Same as above cc = hm.values();
it will give only keys of the entries.