-4

I have a list of Calendars/dates? I have to extract the month's dates from that list and add to new list? How can i do this in java?

use case: list1 contains dates from 20 jan to april 20. I have to separate the dates as jan 20-feb19, feb20-march19, march20-april20. How can i do this in java?

roshan
  • 7
  • 1

2 Answers2

0

This is the perfect use of a for loop

Here is some sudo-code for what you would need to do:

List<Calendar> dates...
List<Integer> months...
for (Calendar calendar : dates){
    months.add(calendar.getMonth());
}
This_Is_Alex_
  • 305
  • 1
  • 6
0

In an ArrayList in JAVA, you can only add an element at the end of the list and not in the middle of this list by example.