Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6253413

java.util.Properties should offer an Iterator<String> for keys

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 5.0
    • core-libs
    • b53
    • x86
    • windows_2000

      A DESCRIPTION OF THE REQUEST :
      java.util.Properties should offer an Iterator for the keys. So far, only the keySet() from the superclass Hashtable can be used for this. But Hashtable has the generic type specification <Object, Object>. So you can't use the for-each loop

      for (String key : p.keySet()) {
          ...
      }

      but only

      for (Object key : p.keySet()) {
          String skey = (String) key;
         ...
      }



      JUSTIFICATION :
      A proper Iterator would made it unnecessary to cast each key Object to String.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Calling keySet() on a Properties object should return Set<String> instead of the Properties superclass Set<Object>.

      ---------- BEGIN SOURCE ----------
      import java.util.Properties;

      public class Test {
          public static void main(String[] args) {
              //iterate through Properties:
              Properties p = System.getProperties();
              for (String key : p.keySet()) { //doesn't work
                  System.out.println(key+": "+p.getProperty(key));
              }
          }
      }

      ---------- END SOURCE ----------
      ###@###.### 2005-04-11 17:56:57 GMT

            mchung Mandy Chung (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: