Daily Archives: November 10, 2008

Iterating through Properties in Java 1.5 is just not right!

I love Java 1.5isms like foreach. It makes me yearn somewhat less for languages like Ruby, Python, and PHP. It makes it so I do not feel itchy when I code in Java. Also I am moving towards Properties instead if Map<String,String> because it seems more “native” – but it is just ugly to iterate through a Properties object in Java:

Properties props ...
for(Object okey : props.keySet() ) {
String key = (String) okey;  // Creepy

What is up with that? And the leys() method returns an Enumeration which does not work with the foreach. What is up with that?