Are Java 8 Streams the same as .Net IEnumerable?

At first I thought Java Streams were necessarily related to I/O but they look really like the IEnumerable interface in .Net.

Is that comparison fair?


Maybe this is something interesting I found on google for you:


Java streams (not to be confused with InputStream and OutputStream) do more or less the same thing as LINQ, with parallel processing mirroring PLINQ. There isn't any nice SQL-like syntax to use, though - you have to do it function-style. And just as LINQ required extension methods, streams don't appear until Java 8 because they need defender methods to work with existing collection types.

Stream is largely equivalent to .NET IEnumerable. To see how they're similar, consider these examples:

// Write each value in a collection to standard output on a separate line:

// C# - LINQ
myCollection.ForEach( x => Console.WriteLine(x) );
// Java - stream x -> System.out.println(x) );

// Sum all the values in a (potentially large) collection, using parallelism
// if possible:

// C# - PLINQ
int sum = myCollection.AsParallel().Aggregate( (x, y) => x + y );
// Java - parallel stream
int sum = (x, y) -> x + y );

You would expect the stream() method to be on Iterable, in the same way as LINQ operates on IEnumerable, but it's on Collection instead. Perhaps it's because Java lacks yield-return semantics, so Iterable is just less interesting or useful in Java.


EDIT: There is a lot to find about it on Google. Here are some more interesting articles:

Need Your Help

Homebrew install permissions issue

osx-snow-leopard homebrew package-managers

I have a standard homebrew install inside of usr/local/

Batch string concatenation in Excel

excel excel-formula concatenation string-concatenation

I have a couple hundred of cells in Excel I would like to concatenate into a single string. Is there a simpler method of doing this than going through them one by one manually in order to type them...