Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method that returns the most recent date

 
Celinio Fernandes
Ranch Hand
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !
 
Mahesh x Bogadi
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 549
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, good idea
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic