Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Using JSR 201 enhanced for loop to iterate over Map values
import java.util.HashMap;
import java.util.Map;
class Scratch {
interface Pool {
void basicDestroy(boolean keepAlive);
static class PoolImpl implements Pool {
public void basicDestroy(final boolean keepAlive) {
public static void main(String[] args) {
final Map<String, Pool> pools = new HashMap<>();
pools.put("First", new PoolImpl());
final boolean keepAlive = true;
// Introduced in Java 1.5 (JSR 201) in 2004 (15 years ago), I give you...the ENHANCED for loop:
for (final Pool pool:pools.values()) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.