Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #33859
| Path | csiph.com!news.swapon.de!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news.mixmin.net!aioe.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: stream filter twice |
| Date | Sun, 21 Feb 2016 09:52:06 -0500 |
| Organization | Aioe.org NNTP Server |
| Lines | 37 |
| Message-ID | <nacium$1fas$1@gioia.aioe.org> (permalink) |
| References | <04334e10-3bad-49dc-87d8-dc2f00f90807@googlegroups.com> <nabaej$1rfq$1@gioia.aioe.org> <ditn2rF45nnU1@mid.individual.net> |
| NNTP-Posting-Host | ANasIS7Js9OyLQwgloeBLQ.user.gioia.aioe.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Complaints-To | abuse@aioe.org |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| X-Notice | Filtered by postfilter v. 0.8.2 |
| Xref | csiph.com comp.lang.java.programmer:33859 |
Show key headers only | View raw
On 2/21/2016 6:58 AM, Robert Klemme wrote:
> On 21.02.2016 04:20, Arne Vajhøj wrote:
>> If the first then I think you current code is fine.
>>
>> If the second then you will need to be creative.
>>
>> Here is my attempt to be creative:
>
> I'm a bit more old fashioned, maybe that's why I do not find the
> advantage of streams so big here.
It saves a bit of typing.
> I was also considering, we might not
> know how large the initial collection is. So the cost of iterating
> twice could be significant.
Yes. That is what my alternative tried to address.
> So:
>
> for (final myClass i : myclasscollection) {
Stream forEach really does the same as this.
> if (i.filter())
> x.add(i);
> else if (i.anotherfilter()) // "else" is optimization!
> y.add(i);
But if we are in micro-optimization mode, then why add to y when we
know that x is non empty?
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
stream filter twice Philipp Kraus <philipp.kraus.flashpixx@gmail.com> - 2016-02-20 04:28 -0800
Re: stream filter twice Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-02-20 08:16 -0500
Re: stream filter twice Arne Vajhøj <arne@vajhoej.dk> - 2016-02-20 22:20 -0500
Re: stream filter twice Robert Klemme <shortcutter@googlemail.com> - 2016-02-21 12:58 +0100
Re: stream filter twice Arne Vajhøj <arne@vajhoej.dk> - 2016-02-21 09:52 -0500
Re: stream filter twice Sebastian <news@seyweiler.dyndns.org> - 2016-02-22 00:13 +0100
csiph-web