0
在HashMap中<字符串,列表
HashMap<String, List<RrdData>> myData
{Data1=[ [Time=1437479200, value=0.8], [Time=1437479201, value=12]], Data2=[[Time=1437479200, value=123], [Time=1437479201, value=78]], Data3=[[fetchTime=1437479200, value=789], [Time=1437479201, value=45]}
我要总结的所述第一值的每个数据,那么第二个值等等。例如:(数组列表的大小不是静态的)
Data1.firstalue + Data2.firstValue+ Data3.firstValue.
Data1.secondValue + Data2.secondValue + Data3.secondValue
所以采用垂直计算的形式。 我写的是它的水平版本。我怎样才能改变它垂直的方式?
for (Entry<String, List<RrdData>> counterEntry : myData.entrySet()) {
final List<RrdData> tempValues = counterEntry.getValue();
for (int i=0; i<length; i++) {
sum += tempValues.getValue(i);
}
}
感谢您的回答。但我有点失落。 d.getValue(i)中的d是什么;? – shirin
对不起。从你的代码中复制了一点点。我现在更新了它。 – Astrogat
但我想要这种形式的值:Data1.firstalue + Data2.firstValue + Data3.firstValue。你提供的总和值为 – shirin