commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodney Waldhoff <rwaldh...@apache.org>
Subject Re: [collections][lang] generic min/max functions
Date Fri, 28 May 2004 21:41:29 GMT
On Tue, 25 May 2004, matthew.hawthorne wrote:

> Emmanuel Bourg wrote:
> > Yes it's an alternative, but at the cost of additional lines to create a
> > collection.
> >
> > Date date = ComparableUtils.min(date1, date2)
> >
> > vs
> >
> > Collection dates = new ArrayList();
> > dates.add(date1);
> > dates.add(date2);
> > Date date = (Date)Collections.min(dates);
>
>
> I see your point now.  But, in the meanwhile, you could always do it
> this way:
>
> Date date = Collections.min(Arrays.asList(new Date[] {date1, date2}))
>
> I'd imagine that this may be a bit wasteful (object-creation wise), but
> it's a one liner nonetheless.
>

Or, for what it's worth:

Date date = date1.compareTo(date2) > 0 date2 : date1;

 - R.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message