Convenient methods in old Iterable
Marcos Antonio
marcos_antonio_ps at hotmail.com
Fri Oct 19 04:51:44 PDT 2012
Thank you, Paul. It helped.
Marcos
> Subject: Re: Convenient methods in old Iterable
> From: paul.sandoz at oracle.com
> Date: Fri, 19 Oct 2012 13:46:26 +0200
> CC: lambda-dev at openjdk.java.net
> To: marcos_antonio_ps at hotmail.com
>
>
> On Oct 19, 2012, at 1:21 PM, Marcos Antonio <marcos_antonio_ps at hotmail.com> wrote:
>
> >
> > Thank you for the answer, Paul. What I meant was that I had code like this: Iterable<Employee> i = employees.filter(...); Now I called i.isEmpty() or i.count(). The code was converted to this: Stream<Employee> s = employees.stream().filter(...); What is the best way to know now if the stream is empty or its count? Thank you. Marcos > Subject: Re: Convenient methods in old Iterable
>
> Ah!
>
> To determine if the stream is empty you can do:
>
> s.iterator().hasNext();
>
> but note that will commit the stream to being pulled based for any further operations on the stream.
>
> To determine the size you have to stuff it into a collection or convert to an array.
>
> I am not very familiar with the old API, but i strongly suspect the implementation would have internally created a collection to determine the size.
>
> Hth,
> Paul.
More information about the lambda-dev
mailing list