Convert old "into" code to the collectors

Marcos Antonio marcos_antonio_ps at hotmail.com
Wed Jan 16 08:38:56 PST 2013


Found a less bulky way:

chave.getPropriedadesChavePai().stream().
    map(PropriedadeChavePai::new).
    forEach(p -> propriedadesChavePai.add(p));

Marcos

----------------------------------------
> From: marcos_antonio_ps at hotmail.com
> To: lambda-dev at openjdk.java.net
> Subject: RE: Convert old "into" code to the collectors
> Date: Wed, 16 Jan 2013 19:25:28 +0300
>
>
> So the bottom line is that I cannot use an existing collection anymore as I used to do with the "into" method, right?
> Are there any alternatives?
>
> For the time being, this is my workaround:
>
> propriedadesChavePai.addAll(
> chave.getPropriedadesChavePai().stream().
> map(PropriedadeChavePai::new).
> collect(Collectors.<PropriedadeChavePai>toList())
> );
>
> Very bulky.
>
> Marcos
>
> ----------------------------------------
> > Date: Wed, 16 Jan 2013 15:58:29 +0000
> > From: maurizio.cimadamore at oracle.com
> > To: marcos_antonio_ps at hotmail.com
> > CC: lambda-dev at openjdk.java.net
> > Subject: Re: Convert old "into" code to the collectors
> >
> >
> > I think the toCollection method is designed to convert a constructor
> > reference (passed as a Supplier) into a new Collector, which is used to
> > carry out the 'collect' operation. In other words, I don't think you can
> > pass a plain collection to 'toCollection'.
> >
> > Maurizio
> > 		 	   		  


More information about the lambda-dev mailing list