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 myCollection.stream().forEach( 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 = myCollection.stream().parallel().reduce( (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: https://web.archive.org/web/20130331002411/http://blog.informatech.cr/2013/03/24/java-streams-preview-vs-net-linq/