If map is a hashmap object, you can use the following two methods to traverse the map:
First, obtain the set of elements and perform operations. The element type is map. Entry.
Object [] O = map. entryset (). toarray (); // obtain the Element Set and convert it to an array.
Map. Entry X;
For (INT I = 0; I <map. Size (); I ++) // traverses the Array
{
X = (Map. Entry) O [I]; // retrieves each element of the array.
Object key = x. getkey (); // obtain the key of this element
Object value = x. getvalue (); // obtain the value of this element.
}
Second: first obtain the set of keys for all elements, and then obtain the value corresponding to each key based on the key.
Object [] O = map. keyset (). toarray (); // first obtain the set of keys and then convert them to an array.
For (INT I = 0; I <O. length; I ++) {// traverses the Array
Object value = map. Get (O [I]); // obtain the specific value based on the key.
}