Code:
Iterator<String> termIncomeKeys = termIncome.keySet().iterator();
while(termIncomeKeys.hasNext()){
String month = termIncomeKeys.next();
System.out.println(month);
}
The month is printed as
Jan(2012) – Jan(2012)
Feb(2012) – Mar(2012)
Apr(2012) – May(2012)
Jun(2012) – Jun(2012)
Jul(2012) – Oct(2012)
What I want to achieve is I want to print the duration in terms of months between each of the entries. That is, Duration between first entry is 1 month, duration between second is 2 and so on.
I do not know if there is a ready-made class that could parse these strings for you, but the logic is simple:
convert the three-letter months to numbers (e.g. 0-11), and convert the years to numbers as well.
The difference is
<year-diff>*12 + <month-diff>, where<month-diff>might be negative.