Tag

entrySet

0 views collected around this technical thread.

Architecture Digest
Architecture Digest
May 13, 2025 · Fundamentals

Understanding HashMap Traversal: keySet vs entrySet and Iterator Mechanics

This article explains the various ways to traverse a Java HashMap, compares keySet and entrySet approaches, shows why keySet involves two passes, and demonstrates the underlying iterator implementation with detailed code examples and decompiled snippets.

HashMapIteratorJava
0 likes · 8 min read
Understanding HashMap Traversal: keySet vs entrySet and Iterator Mechanics
Architect's Guide
Architect's Guide
Sep 9, 2024 · Fundamentals

Why HashMap.keySet() Traversal Performs Two Iterations and How entrySet() Is More Efficient

This article explains the internal mechanism of Java's HashMap traversal, showing that using keySet() triggers two passes—once to create an iterator and once to fetch values—while entrySet() or Map.forEach() can iterate in a single pass, and it walks through the relevant source code to illustrate the process.

HashMapIteratorJava
0 likes · 9 min read
Why HashMap.keySet() Traversal Performs Two Iterations and How entrySet() Is More Efficient
Code Ape Tech Column
Code Ape Tech Column
Nov 10, 2023 · Fundamentals

Why HashMap.keySet() Traversal Performs Two Passes While entrySet() Traversal Performs One

This article explains the internal mechanics of HashMap traversal in Java, showing that keySet() uses an iterator that iterates twice to locate entries, whereas entrySet() (or Map.forEach) iterates only once, and it walks through the relevant source code and decompiled bytecode to illustrate the process.

HashMapIteratorJava
0 likes · 8 min read
Why HashMap.keySet() Traversal Performs Two Passes While entrySet() Traversal Performs One
Top Architect
Top Architect
Jul 23, 2022 · Backend Development

Four Methods to Traverse a Java Map Using keySet, entrySet and Iterators

This article demonstrates four practical ways to iterate over a Java HashMap—including enhanced for loops with keySet(), iterator-based loops with keySet(), enhanced for loops with entrySet(), and iterator-based loops with entrySet()—and provides a complete example that filters employee objects by salary, complete with full source code.

CollectionsHashMapIterator
0 likes · 10 min read
Four Methods to Traverse a Java Map Using keySet, entrySet and Iterators