Friday, May 3, 2019

java - How to for each the hashmap?





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);
}
}

Answer



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.
}


No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...