Convert list to map

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Convert list to map

Danny Lagrouw
Hi all,

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());
}
});

Does something like this exist?
--
Regards,
Danny Lagrouw
Java Developer, Profict b.v.
Reply | Threaded
Open this post in threaded view
|

Convert list to map

Danny Lagrouw
Hi all,

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());
}
});

Does something like this exist?
--
Regards,
Danny Lagrouw
Java Developer, Profict b.v.