I have an ArrayList of HashMap elements that has a format of Category, Activity and Time. I.E.
{CATEGORY=Planning, ACTIVITY=Bills, TIME=5}
{CATEGORY=Planning, ACTIVITY=Bills, TIME=7}
{CATEGORY=Planning, ACTIVITY=Meetings, TIME=10}
{CATEGORY=Resources, ACTIVITY=Room1, TIME=15}
....
Take note of the CATEGORY/ACTIVITY pair that is repeated as that can happen in the List
I need to be able to convert this List into a multidimensional one. The best way I can think of for how this List needs to look is by writing some pseudocode…please see that at the bottom of the post.
I’ve thought of several different approaches on how to implement this but I’m quite frankly stuck and frustrated at how to do this. I’ve thought of taking the inefficient approach of looping through the ArrayList several times in outer and inner loops but I know that wouldn’t be good coding practice.
Any suggestions on how I can implement this conversion so I can loop like in the pseudocode below?
For CATEGORY in CATEGORIES {
CategoryTime = 0
Display Category Header
For ACTIVITY in ACTIVITIES {
Activity Time = 0
For TIME_RECORD in ACTIVITY
Add time to activity total time, category total time & grand total
}
Display Activity Total
}
Display Category Total
}
Display Grand Total and rest of information...
Edit
I appreciate all the feedback given for this problem and it appears that really the best way to go is to enhance a class that the ArrayList of HashMap elements is a member of.
I’ve put in a vote to close this question as has another person as it’s too localized. I would appreciate it if some of you other developers would follow suit to close the question. I would delete it but I can’t at this point because there are answers to the question.
I would write a class that looks like so:
Then you should be able to do the following: