[robsite.org]

« Getting the Environment in JDK 1.5 | Main | Java 5.0 fixed one of my bugs DnD Bugs. »

September 30, 2004

Getting the Environment in JDK 1.5 (update)

As soon as I posted this, I realized that it could be simplified a bit by using the new for syntax in Java 5.0. Here's an updated snippet:

  Map<String, String> environment = System.getenv();
  for( Map.Entry<String,String> entry : environment.entrySet() )
  {
    String key = entry.getKey();
    String value = entry.getValue();
    System.out.println( "[" + key + " = " + value + "]");
  }

Posted by rcleveng at September 30, 2004 12:04 PM

Comments

The newer style of syntax is different and will take quite some time before we are used to it. For me personally, the older syntax rolls off my keyboard without thinking about it, however it didn't years ago when I first started using it. Only time will tell if the new syntax appears "simpler" in a year from now or not. I think it will.

-- Rob

Posted by: Rob at October 3, 2004 10:56 AM

This is not simplified! Shorter? Yes.
Simpler? Arguable, and IMO no.

Posted by: Shai at October 3, 2004 06:38 AM