I have an ArrayList where I want to call two methods on the first two objects in the list, and different methods on the rest, how can I do this the easiest way?
So far I have this
ArrayList<Material> materials = new ArrayList();
StyklisteMetodeKlasse.fillArray(materials);
for(Material materialer: materials.subList(0, 1)){
int brugerInput = 0; // this is only a temporary varible
materialer.setAmount(Material.calculatePlanks(brugerInput, materialer.getLength()));
materialer.setAmount(Material.calculatePlanks(brugerInput, materialer.getLength()));
//here is some code where i call different methods on the rest of the materials
When I call a method on the "materialer" does it apply for all the objects or just the first, then the second?
materials.subList(0, 1)gives you a sublist with only the first element. So in this case you're only callingsetAmountfor the first element. But if you change it tosubList(0, 2), you'll be callingsetAmountfor the first two elements.A()on, and the rest on which you want to call methodB()on, without any additional criteria? If so, why not just split the list?