I want to go through every items in a dictionary in java. to clarify what I want to do, this is the C# code
Dictionary<string, Label> LableList = new Dictionary<string, Label>();
foreach (KeyValuePair<string, Label> z in LabelList);
I don’t know how to do this is java, for example I did this
for(Object z: dic)
but it says it’s not iterable. Please advise……
I’m assuming you have a
Map<String, Label>which is the Java built-in dictionary structure. Java doesn’t let you iterate directly over aMap(i.e. it doesn’t implementIterable) because it would be ambiguous what you’re actually iterating over.It’s just a matter of choosing to iterate through the keys, values or entries (both).
e.g.
Your C# code seems to be the same as iterating over the entries (the last example).