-
Enhancement
-
Resolution: Not an Issue
-
P4
-
None
-
6
-
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
}
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
}
- relates to
-
JDK-6312085 enhanced-for statement (for-each loop) should support Iterator
-
- Closed
-
-
JDK-6524774 Nested for loops in Java
-
- Closed
-