I have an ArrayList of String[].
Each String[] contains two values: value and date.
If I print it, it will look something like this:
value | date -------|---------- 357.0 | 2011/05/30 -234.0 | 2011/05/31 -123.0 | 2011/05/30
i want to make a new ArrayList, where all values in same date are summed. Like this:
value | date -------|---------- 234.0 | 2011/05/30 -234.0 | 2011/05/31
Can anyone help?
You too, are suffering from object denial.
Stringis not a good type for handling numbers or dates. For a number I’d useint(if you only have integer values),doubleorBigDecimal(if it’s a monetary ammount or some other exact decimal number).For the date I’d use either a
Date/CalendarorLocalDatefrom Joda Time (if you can use an external library).Obviously this means that you can no longer store your data in a
String[], but that’s not really an appropriate type for any kind of structured data, anyway.You’d want to write a class that reflects what your values are about:
Then you can simply create the new values by iterating over the original
ArrayList<DatedValue>: