HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavaCritical

How to for each the hashmap?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howtheforhashmapeach

Problem

I have this field:

HashMap selects = new HashMap();


For each Hash I need to create a ComboBox, whose items are the value (which happens to be a HashMap itself) of HashMap .

By way of (non-functioning) demonstration:

for (int i=0; i < selects.size(); i++) {
    HashMap h = selects[i].getValue();
    ComboBox cb = new ComboBox();

    for (int y=0; y < h.size(); i++) {
        cb.items.add(h[y].getValue);
    }
}

Solution

I know I'm a bit late for that one, but I'll share what I did too, in case it helps someone else :

HashMap selects = new HashMap();

for(Map.Entry entry : selects.entrySet()) {
    String key = entry.getKey();
    HashMap value = entry.getValue();

    // do what you have to do here
    // In your case, another loop.
}

Code Snippets

HashMap<String, HashMap> selects = new HashMap<String, HashMap>();

for(Map.Entry<String, HashMap> entry : selects.entrySet()) {
    String key = entry.getKey();
    HashMap value = entry.getValue();

    // do what you have to do here
    // In your case, another loop.
}

Context

Stack Overflow Q#4234985, score: 1425

Revisions (0)

No revisions yet.