I'm really new to Java, and was wondering if someone could help me convert the following to foreach loops into for loops?
Assuming expression is a collection of items:
for(Type x: expression){
...
for(Type y: x.expression){
.....
}
}
I'm really new to Java, and was wondering if someone could help me convert the following to foreach loops into for loops?
Assuming expression is a collection of items:
for(Type x: expression){
...
for(Type y: x.expression){
.....
}
}
expression needs to be some kind of collection of items. The for (Type item : items) loop just iterates over all of them.
To manually loop over the collection you just need the length of the collection and can use:
for (int i = 0; i < collection.size(); i++) { // or .length() if it is an array
Type item = collection.get(i); // or collection[i] if it is an array
}
Type needs to be the type of the items in the collection.