HashMap Methods and its use Flashcards

1
Q
  1. What is the difference between remove (key) and remove(key, value ) pair?
  2. What is the use of put, put all, remove(Key) and remove(Key value) , get(key), clear(), size(), isEmpty()., replace, replaceall().
  3. Does collection have length or Size?
A
  1. If we give remove (key) we will get the value in output.
    If we give remove(Key, value) we will get true .
  2. 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.

  1. Collections have only size , length is used for Strings and Arrays.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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?

A

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().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. What are all the Interfaces you know?
  2. What are the methods entry have?
  3. What is map.entry?
A
  1. Collection, List, Set comparator, comparable, navigableset, sorted set, navigablemap,
  2. getkey(), get value() return type for this is Object
  3. Without map there is no entry so we use Map.entry
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What is the use of entryset()
    2.What is the use of collectionvalues
    3..What is the use of keyset
A
  1. 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
  2. Same as above Collections cc = hm.values();
    it will give only values of the entries.
  3. Same as above cc = hm.values();
    it will give only keys of the entries.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly