mercredi 6 juillet 2016

Sort multiple relative Lists in Java

I have seen other similar questions - but people are unable to understand those questions well to give good solutions - so ill try to do better...

I have two lists, one for Events names and one for events times

List<String> eventNames= new ArrayList<String>();
List<Calendar> eventTimes= new ArrayList<Calendar>();

There is a 1 to 1 relation between these lists, so the first item in eventNames is related to the first item of eventTimes...and same for the second items, the third...etc..

I can use the following to order eventTimes in ascending order:

Collections.sort(eventTimes, new Comparator<Calendar>() {
    public int compare(Calendar c1, Calendar c2) {
        return c1.getTime().compareTo(c2.getTime());
    }
});

but I want to sort both of these lists by the times of the events in eventTimes.

I believe I need to 'Map' these lists...? but I don't understand how to do that?

Aucun commentaire:

Enregistrer un commentaire