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 LableList = new Dict
I'm assuming you have a Map
which is the Java built-in dictionary structure. Java doesn't let you iterate directly over a Map
(i.e. it doesn't implement Iterable
) 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.
Map map = new HashMap();
//...
for ( String key : map.keySet() ) {
}
for ( Label value : map.values() ) {
}
for ( Map.Entry entry : map.entrySet() ) {
String key = entry.getKey();
Label value = entry.getValue();
}
Your C# code seems to be the same as iterating over the entries (the last example).