Performance tip: If you want to iterate over the keys and values use entrySet()

Overview

Using entrySet() is the fastest way to get all the keys with their values.

Don't use keySet() with get()

From AnimationController.actionPerformed()
for (Part part : map.keySet()) {
    if (map.get(part).isDone()) {
        if (partsToRemove == null) {
            partsToRemove = new ArrayList();
        }
        partsToRemove.add(part);
    }
}
Using get() is much more expensive than Entry.getValue().
for (Map.Entry entry : map.entrySet()) {
    if (entry.getValue().isDone()) {
        if (partsToRemove == null) {
            partsToRemove = new ArrayList();
        }
        partsToRemove.add(entry.getKey());
    }
}

Comments

Popular posts from this blog

Low Latency Microservices, A Retrospective

Unusual Java: StackTrace Extends Throwable

System wide unique nanosecond timestamps