arraylist help!
i was wondering if anyone could tell how to sum objects in an arraylist?
# 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 ?
# 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
}