arraylist help!

i was wondering if anyone could tell how to sum objects in an arraylist?
[79 byte] By [da_master_of_nuthin] at [2007-11-26 12:17:32]
# 1
Sure. Iterate through the list and add things up.
CeciNEstPasUnProgrammeur at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...
# 2
I guess it depends on the type of objects contained in the list.Anyway, you will have to iterate through the elements of the list, and apply adequate operator/method for summing them.Would you tell us what causes you problem exactly ?
TimTheEnchantor at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...
# 3
do i need to do a while loop?
da_master_of_nuthin at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...
# 4
So which of the recommendations received in your previous thread you have followed in this thread?Mike
bellyripper at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...
# 5

A for loop is more resonable:

for(int i = 0; i < myArrayList.size(); i++){

//whatever

}

If you using Java 1.5, a foreach loop is even better.

ArrayList<Integer> myArrayList = new ArrayList<Integer>();

...

for(Integer i: myArrayList){

//whatever

}

Lumantu at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...
# 6
> A for loop is more resonable:Using a ListIterator is sometimes even more reasonable.
CeciNEstPasUnProgrammeur at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...
# 7
use any type of loop.. for , while.. if you can invent yours
G_Abubakr at 2007-7-7 14:55:12 > top of Java-index,Archived Forums,Socket Programming...