Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know there are classes like hashset that can remove duplicates but I doubt I can apply it to my case.
I have a list of dates, separated into month and day respectively.
Java
private static List<MonthDay> Dates() {
		List<MonthDay> dates = new ArrayList <MonthDay>();
		dates.add(MonthDay.of(JAN, 1));
		dates.add(MonthDay.of(JAN, 2));
		dates.add(MonthDay.of(FEB, 3));
		dates.add(MonthDay.of(MAR, 1)); 
                return dates;
}


I've also created a method to return lists of specified dates.
Java
private static List<MonthDay> Month(Month month) {
    List<MonthDay> monthList = new ArrayList<>();
    for (MonthDay m : Dates()) {
        if (m.getMonth().equals(month)) {
            monthList.add(m);
        }
    }
    return monthList;
}


Now, I want to have a method to check whether my month is unique or not, and then return a <monthday> list of the dates containing the unique months.
e.g. FEB and MAR are unique months in the list, so the output I should get is [--02-03, --03-01]

How do I go about doing so?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900