The question is, "We might expect method3 to run faster than method2, why is that?" but I have no idea. It seems like both methods do the same amount of operations. Could someone please enlighten me?
ArrayList<Person> method2(Person x, ArrayList<Person> people){
ArrayList<Person> friends = new ArrayList<Person>();
for (Person y : people) if (x.knows(y)) friends.add(y);
return friends;
}
ArrayList<Person> method3(Person x, ArrayList<Person> people){
ArrayList<Person> friends = new ArrayList<Person>();
for (int=0; i<people.size(); i++){
Person y = people.get(i);
if (x.knows(y)) friends.add(y);
}
return friends;
}