Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #37717
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2017-12-04 07:14 -0800 |
| References | (1 earlier) <ovshh6$8q1$1@dont-email.me> <a7f8b0f0-79cb-4f83-bf77-2ce7d94a2a19@googlegroups.com> <p03i39$n76$1@dont-email.me> <9545f24b-39da-4eab-8c65-365a299b3b2a@googlegroups.com> <p03m3p$ihc$1@dont-email.me> |
| Message-ID | <a706de3b-eafe-47c9-8144-b1ceb04bc495@googlegroups.com> (permalink) |
| Subject | Re: Can I put a filter into a lambda? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Monday, December 4, 2017 at 9:29:33 AM UTC-5, Eric Sosman wrote: > If you'd rather clear and repopulate the same List (as opposed > to making a new one each time), you could use forEach(): > > rowModelIndex.clear(); > IntStream.range(0, modelRowCount) > .filter((value) -> include(value)) > .forEach((value) -> rowModelIndex.add(value); > > or > > rowModelIndex.clear(); > IntStream.range(0, modelRowCount) > .forEach((value) -> > if (include(value)) rowModelIndex.add(value)); > > I don't know which of these might be faster, or whether either > might be faster than a plain old `for' loop. (Research project.) > Thanks! I'll check it out. > FWIW, Brian Goetz (who knows far more about JVM performance > issues than I ever will) indicates that object allocation and > collection is cheaper than commonly thought, so there's little > if any advantage to re-using the same List object: > > https://www.ibm.com/developerworks/java/library/j-jtp09275/index.html > > ... which means even more research may be indicated. (The cited > article is twelve years old, and we may expect that JVM's have > continued to improve meanwhile). > I'd have to take another look at their code for clear() and addAll(), I would guess generating a new variable might be cheaper, but the functional difference is more important. I'd have to check if I have something else grabbing a reference to this variable just expecting it to get updated values rather than needing to get the reference to a new variable. I believe I did that, though offhand can't recall why.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-01 12:52 -0800
Re: Can I put a filter into a lambda? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-01 16:28 -0500
Re: Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-04 05:03 -0800
Re: Can I put a filter into a lambda? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-04 08:20 -0500
Re: Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-04 05:32 -0800
Re: Can I put a filter into a lambda? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-12-04 09:29 -0500
Re: Can I put a filter into a lambda? Eric Douglas <e.d.programmer@gmail.com> - 2017-12-04 07:14 -0800
Re: Can I put a filter into a lambda? Sebastian <nowhere@nirvana.org> - 2017-12-08 15:00 +0100
csiph-web