commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Dunning <ted.dunn...@gmail.com>
Subject Re: Convert List to Map
Date Thu, 11 Jun 2009 21:12:10 GMT
How is this easier than this:

Map m = new HashMap();
for (SpecificObject x : list) {
    m.put(s.getId(), s.getDescription());
}

?

Why make this soo much harder than it needs to be?

On Wed, Jun 10, 2009 at 12:19 PM, Adrian Gonzalez <adr_gonzalez@yahoo.fr>wrote:

> Hello,
>
> I have the same question as
> http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@mail.gmail.com%3E:
>
> I need to do a lot of list-to-map conversions, and I'm looking for a way to
> use commons collections for this.
> I would like to do something like this:
>
> Map map = ListUtils.toMap(list, new SomeTransformerInterface() {
>    void insertIntoMap(Object object, Map map) {
>    SpecificObject s = (SpecificObject) object;
>    map.put(s.getId(), s.getDescription());
>    }
> });
>
> Is there a way to do that with commons collection ?
>
> Thank you very much
>
>
>




-- 
Ted Dunning, CTO
DeepDyve

111 West Evelyn Ave. Ste. 202
Sunnyvale, CA 94086
http://www.deepdyve.com
858-414-0013 (m)
408-773-0220 (fax)

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message