Java sorts a collection of date and time values
•
Java
I'm using notes Jar Lotus Notes API to extract the date and time of E - mail When I add them to the collection, if I add them like this:
Vector times = doc.getItemValueDateTimeArray("PostedDate"); for (int j=0; j<times.size(); j++) { Object time = times.elementAt(j); if (time.getClass().getName().endsWith("DateTime")) { String Listadd = ((DateTime)time).getLocalTime(); NotesDates.add((DateTime)time);
I received an error:
lotus.domino.local.DateTime cannot be cast to java.lang.Comparable
When I add a value as string, the code runs, but I can't sort the collection
How do I sort a collection of dates and times to find the oldest and most recent?
Solution
You have several choices These are two
>Using Java util. A collection of dates instead of lotus domino. local. Datetimelotus annotation datetime object has a method tojavadate(), Java util. Date implements the comparable interface for you > lotus domino. local. The datetime object implements a custom comparator It's better to convert the date to Java date again and use its comparison method instead of reinventing the wheel
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码