API question/request: Array to Stream
Per Bothner
per at bothner.com
Tue Oct 1 07:29:44 PDT 2013
On 10/01/2013 07:16 AM, Paul Sandoz wrote:
>
> On Oct 1, 2013, at 3:24 PM, "Millies, Sebastian" <Sebastian.Millies at softwareag.com> wrote:
>
>> Why can't I stream an array? It is awkward having to convert to a list first, cf.
>> this code by Venkat Subramaniam:
On 10/01/2013 07:16 AM, Paul Sandoz wrote
> Use:
>
> Stream.of(filters)...
Better, IMO: Arrays.stream(filters), for 2 reasons:
(1) Arrays.stream has options startInclusive/endInclusive bounds.
If you have an array buffer that's not necessary full, then you
need the endInclusive (though admittedly an alternative is Stream#limit).
(2) As a matter of style, Stream#of is a varargs method: It takes a
variable number of T, not an array of T. True, variable number of T
is implemented as (and effectively overloaded as) an array of T,
but Java varargs is a bit of a hack and and using ivarargs to pass a
single array is less readable I think.
--
--Per Bothner
per at bothner.com http://per.bothner.com/
More information about the lambda-dev
mailing list