What do you do with HashMap when you turn the repeat door?

Asked 2 years ago, Updated 2 years ago, 184 views

You want to check the data of an object in HashMap How do I turn the repeat statement on HashMap?

loops java hashmap iteration

2022-09-22 22:37

1 Answers

public static void printMap(Map mp) {
    Iterator it = mp.entrySet().iterator();
    while (it.hasNext()) {
    Map.Entry pair = (Map.Entry)it.next();
    System.out.println(pair.getKey() + " = " + pair.getValue());
    it.remove(); // avoids a ConcurrentModificationException
    }
}

Write "Iterator" and spin it!


2022-09-22 22:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.