Originally I have been using arraylists like this:
ArrayList<JavaBean> AllBeans = new ArrayList<JavaBean>();
And I'm able to iterate through it and get it to print all of my beans like this:
for (int i=0;i<AllBeans.size();i++){
System.out.println(AllBeans.get(i).getCost());
}
But I found out I should be doing this:
Collection<JavaBean> AllBeans = new ArrayList<JavaBean>();
But if I do that, I no longer can do AllBeans.get(i).getCost(), so I read on stackoverflow, and I apparently need to user an iterator. But, I don't understand what I'm doing. I want to be able to use the original bean classes, but I can't get to them? I just want to use my bean.getCost() from my bean object.
The only thing I could get was
Iterator itr = new AllBeans.Iterator();
while (itr.hasNext()){
System.out.println(itr.next().toString())
}
Which doesn't get to my object at all? I'm still having trouble understanding abstract and interface in java.