Java tutorial
//package com.java2s; //License from project: Apache License import android.util.SparseArray; import java.util.ArrayList; public class Main { public static float averageValueOfCompartments(SparseArray<ArrayList<Float>> compartments) { return sumCompartmentsValues(compartments) / compartments.size(); } public static float sumCompartmentsValues(SparseArray<ArrayList<Float>> compartments) { float sum = 0L; for (int i = 0; i < compartments.size(); i++) { for (int j = 0; j < compartments.get(i).size(); j++) { sum += compartments.get(i).get(j); } } return sum; } }