I have a map that is updated from Firebase Realtime Database, so I don't know the map size in advance.
In the map I have a String as key, and a Joda DateTime
as value.
I don't know how to iterate through the map to return the most recent Datetime.
I'll try to explain better:
//on returning results from Realtime Database
Map<String, DateTime> myMap = new HashMap<>();
if(dataSnapshot.exists){
for(DataSnapshot data:dataSnapshot.getChildren()){
String key = data.getKey();
DateTime dateTime = // I get the data and convert it to Datetime; no problem here; I can do it.
myMap.put(key, dateTime);
}
//outside the Loop
//HERE IS WHAT I NEED HELP WITH
for(DateTime date:myMap.values()){
// 1 - check if date is after the next date in map
// 2 - if it is, then keep it
// 3 - if it is not, then remove
// 4 - in the end, only one pair of key/value with the most recent date is left
}
}
Can you guys please, help me? Thank you so much
EDIT: Sorry, one more thing. I'm using a minimum sdk in Android that doesn't ler me use Java 8. I have to use Java 7 features.