How can i iterate through 2 collections at the same time?
Could i do it with just one iterator?
Both collections are the same size.
p.s. Can you use example code if possible?
Thanks.
Printable View
How can i iterate through 2 collections at the same time?
Could i do it with just one iterator?
Both collections are the same size.
p.s. Can you use example code if possible?
Thanks.
What is the purpose of this iteration?
If you are just comparing two collection:
Code:public class Smaple {
public static void main(String args[]) {
int collection1[] = {1,2,3,4,5}
, collection2[] = {1,2,3,4,5}
, x = 0;
for (int i = 0; i < collection1.length; i++) {
if (collection1[i] == collection2[i]) {
x++;
}
}
}
}
I need to execute the print method of each object in both collections in a specific order. Like this:Quote:
Originally Posted by ComputerJy
Collection1[1].print()
Collection2[1].print()
Collection1[2].print()
Collection2[2].print()
Collection1[3].print()
Collection2[3].print()
Collection1[4].print()
Collection2[4].print()
and so on...
To be more specific
I have a dating system (uni coursework) that is meant to match male and female customers. I am doing this the simple (gaining slightly lower marks) way.
I have two collections :- maleCust and femaleCust, both contain Customer objects.
I want to match the first male with the first female found in both collections, and so on... I think an iterator would be perfect for this.
put it in a nested for loop