This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes method that returns the most recent date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "method that returns the most recent date" Watch "method that returns the most recent date" New topic
Author

method that returns the most recent date

Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

Hi,
Has anyone ever written a method that takes an illimited number of dates, checks if they are null or not, returns the most recent one ?

Date Mostrecent(Date date1, Date date2, Date date3, ...) {}

Or any ideas on how to implement it ?

Thanks in advance !


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCBCD 5
Visit my blog
Mahesh x Bogadi
Ranch Hand

Joined: Jul 06, 2004
Posts: 51
you can convert any Date to a long.

So convert all the Dates to Longs. sort them.
The highest value will be the recent date
Celinio Fernandes
Ranch Hand

Joined: Jun 28, 2003
Posts: 547

thanks, good idea
Stuart Gray
Ranch Hand

Joined: Apr 21, 2005
Posts: 410
You could also just put the values into a an implementation of the Sorted interface (e.g. TreeSet) then pull out the last value, which will be the most recent one.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
And look at the Java 5.0 syntax for variable number of parameters. The caller can call with one or two or ten or whatever, the method is written to treat them as an array.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: method that returns the most recent date
 
Similar Threads
how to compare a Date and a Calendar date ?
Find Calling Class' name within Called Class
Conversion of string to date
I Need Help With a Derby SQL Join Statement
Pls put the "search" back :-(