Lets say that we have a collection of items. Which of the two is faster?
HashMap<String, ObjectFoo> hashmap = new HashMap<String, ObjectFoo>();
/* .... add elements .... */
ObjectFoo theElement = hashmap.get("nameOfObject");
Or
ArrayList<ObjectFoo> arraylist = new ArrayList<Object>();
/* .... add elements .... */
Iterator<ObjectFoo> itFoo = arraylist.iterator();
ObjectFoo obj;
while(itFoo.hasNext()) {
obj = itFoo.next();
if (obj.name.equals("nameOfObject")) return obj;
}
Suppose that:
public class ObjectFoo {
public String name;
}