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

Allow to use CharSequence in foreach loop

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 5.0
    • specification
    • x86
    • windows_xp

      Name: js151677 Date: 07/02/2004


      A DESCRIPTION OF THE REQUEST :
      JSR 201 propose a for loop (foreach) specifically designed for iteration over collections and arrays.
      I propose to extend foreach loop to CharSequence.

      JUSTIFICATION :
      Java 1.5 introduced some new API to improve the way
      how java handle character input/output processing
      like Scanner or Readable
      but doesn't provide support to iterate over strings.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      for(char c:s) {
        System.out.println(c);
      }


      ACTUAL -
      for(int i=0;i<s.length();i++) {
        char c=s.charAt(i);
        System.out.println(c);
      }

      CUSTOMER SUBMITTED WORKAROUND :
      use classical for loop.
      (Incident Review ID: 282288)
      ======================================================================

            abuckley Alex Buckley
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: