> I've found that I often need to iterator over a Map and do something
> to each element of the Map. The only way I've found to do this is to
[quoted text clipped - 22 lines]
>
> Any advice appreciated.
Iterator<String> it = map.values().iterator();
HTH.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
> I've found that I often need to iterator over a Map and do something
> to each element of the Map. The only way I've found to do this is to
[quoted text clipped - 22 lines]
>
> Any advice appreciated.
What is preventing you from using the new loop syntax with the Map?
import java.util.HashMap;
import java.util.Map;
public class MapTest {
public static void main(String[] args) {
Map<String,String> myMap = new HashMap<String,String>();
myMap.put("x","a");
myMap.put("y","b");
System.out.println("Values only");
for(String value: myMap.values()){
System.out.printf("Value: %s%n",value);
}
System.out.println("Keys and values");
for(Map.Entry<String,String> entry: myMap.entrySet()){
System.out.printf("Key: %s, Value: %s%n",
entry.getKey(),entry.getValue());
}
}
}
Patricia
dsh0105@gmail.com - 07 Feb 2007 03:36 GMT
> dsh0...@gmail.com wrote:
> > I've found that I often need to iterator over a Map and do something
[quoted text clipped - 48 lines]
>
> Patricia
The only think preventing me from using the new looking was a mental
block:). It's obvious now. How embarrassing. Thanks for the help.