toMap method in Collection

Neal Gafter neal at gafter.com
Sat Nov 19 18:24:04 PST 2011


Presumably the result would be a multimap, not a map, as multiple values
could have the same key.  In .NET we call this method GroupBy.

On Sat, Nov 19, 2011 at 8:48 AM, Marcos Antonio <
marcos_antonio_ps at hotmail.com> wrote:

>
>
>
>
> Hello, everybody! Now that Java 8 will have lambda and extension methods,
> don't you think that a 'toMap' methodwould be another useful method to be
> added to the Collection interface? For example: Set<Employee> employees =
> ...Map<Integer, Employee> emp = employees.toMap(Employee::getID); Now 'emp'
> is a map with Employee objects as values and the employees' ids as keys. So
> themap values are always the elements of the collection, but the user is
> free to choose what the mapkey will be. Thank you. Marcos
>
>


More information about the lambda-dev mailing list