add a count to a year number
in
Programming Questions
•
2 years ago
I have the years 1890 till 2011.
I need to count certain things so it can end up with
2011 = 4
2010 = 2
2009 = 8
2008 = 8
2007 = 12
etc.
Here is a part of my code, i looked at example but by me there are 2 hasmaps involved which is really confusing me.
Basicly i go threw the songs_hm hashMap, it contains a class which holds year numbers, for every year it holds i need to increase the count for that year.
So if i'm correct i only need to do something here:
//increase count for that year
// ?
Which will be get the old value and readd it with the oldvalue +1.
(if you know a way better method that may not contain a hashmap then that's also fine)
I need to count certain things so it can end up with
2011 = 4
2010 = 2
2009 = 8
2008 = 8
2007 = 12
etc.
Here is a part of my code, i looked at example but by me there are 2 hasmaps involved which is really confusing me.
Basicly i go threw the songs_hm hashMap, it contains a class which holds year numbers, for every year it holds i need to increase the count for that year.
So if i'm correct i only need to do something here:
//increase count for that year
// ?
Which will be get the old value and readd it with the oldvalue +1.
(if you know a way better method that may not contain a hashmap then that's also fine)
- HashMap reCharted_years_hm = new HashMap();
Iterator k = songs_hm.values().iterator();
while (k.hasNext()) {
Song s = (Song) k.next();
if (s.count > 1) {
for (int j = s.years.length-1; j >= 0; j--) {
if (reCharted_years_hm.containsKey(s.years[j])) {
//increase count for that year
// ?
}
else {
reCharted_years_hm.put(s.years[j], int(1));
}
}
}
}
1