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

Enhance the new for loop to loop over 1 or more collections

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6
    • specification
    • x86
    • linux

      A DESCRIPTION OF THE REQUEST :
      When using the new for loop for iterating over collections, there is no way to specify more than one collection to iterate over.

      JUSTIFICATION :
      When dealing with collections of different datatypes that have to be joined over a loop iterators are used instead of get() methods, for an actual or expected performance advantages. This leads to a lot of boilerplate code of declaring iterators over various collections and calling next() over them, when ideally the
      new for loop should simplify the process.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -

      for(Object o : list1, int i : list2, String s : list3){
      do something
      }
      ACTUAL -
      ListIterator <Integer> it1 = list2.getListIterator();
      ListIterator <String> it2 = list3.getListIterator();
      int i;
      String s;
      for(Object o : list1){
      i = it1.next();
      s = it2.next();
      do something
      }

            abuckley Alex Buckley
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: