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

String and StringBuffer should be allowed in 'foreach' construct

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      there is no reason that this shouldn't work:

        String text = "whatever"
         for (char c : text) { ... }


      JUSTIFICATION :
      this is exactly the reason that the 'foreach' construct was added - to simplify code where you're iterating over containers with similar values. it should be trivial to implement.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the above syntax should work.
      ACTUAL -
      you need this more complex code:

        String text = "whatever"
        for (int i = 0, len = text.length(); i < len; i++) {
          char c = text.charAt(i);
          ...
        }
      ###@###.### 2005-05-24 05:21:23 GMT

            nlindenbsunw Norbert Lindenberg (Inactive)
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: