Iterator in Map. Flashcards

1
Q
  1. What is Iterator?
  2. How to Iterate a Entries ?
  3. Do you know while loop condition?
  4. What is the use of hasnext.
A
  1. Iterator is an interface in java, by using Iterator we can get all the entries in entry set.
  2. First change alll the key value pairs to entry set by using
    Set s = cc.entrySet(); cc is the refrence name create while hashmap.
  3. Yes i know,

Iterator i -= s.iterator;
while(i.hasnext())
{
system.out.println(i.next();

)
But using this it will print the value in entries key value pair

4.hasnext() it is like a condition it will check whether any values are the next.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly