Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33356
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: streams list in list reduce |
| Date | Wed, 16 Dec 2015 21:14:07 -0500 |
| Organization | Aioe.org NNTP Server |
| Lines | 50 |
| Message-ID | <n4t5pf$96b$1@speranza.aioe.org> (permalink) |
| References | <3360df16-6ac2-4ee4-b6b4-2fcaac9e6aa7@googlegroups.com> |
| NNTP-Posting-Host | 1lM8B9/qdtKBc/uIRK2Gjw.user.speranza.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.java.programmer:33356 |
Show key headers only | View raw
On 12/16/2015 5:52 AM, Philipp Kraus wrote:
> I have got a definition like
>
> interface Execute { Collection<Term> exec(); }
>
> and run vai streams over my data
>
> List<Execute> x; // x is filled
>
> And I would like to create List<Term> y = x.stream().map( i ->
> i.exec()).collect( ?? toList() );
>
> I would like to run addAll on the collect and build a concatinated
> list if all lists which are return by the exec method. How can I
> create this concatinated list?
Demo of one approach:
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class LotsOfLists {
public static interface Execute
{
public Collection<Integer> exec();
}
public static class ExecuteImpl implements Execute {
private List<Integer> data = new ArrayList<>();
public ExecuteImpl(int... vals) {
for(int val : vals) data.add(val);
}
@Override
public Collection<Integer> exec() {
return data;
}
}
public static void main(String[] args) {
List<Execute> x = new ArrayList<>();
x.add(new ExecuteImpl(1));
x.add(new ExecuteImpl(2, 3));
List<Integer> res = x.stream().collect(ArrayList<Integer>::new,
(acc,elm) -> acc.addAll(elm.exec()), ArrayList<Integer>::addAll);
System.out.println(res);
}
}
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
streams list in list reduce Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-16 02:52 -0800
Re: streams list in list reduce Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-12-16 09:23 -0500
Re: streams list in list reduce Arne Vajhøj <arne@vajhoej.dk> - 2015-12-16 21:14 -0500
Re: streams list in list reduce Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2015-12-16 23:41 -0800
csiph-web