Java Streams Preview vs .Net LINQ


I’ve started following this very promising blog by the “Geeks From Paradise”. Apart from the fact that I’m a bit envious of geeks living in Costa Rica, this comparison of the upcoming Java 8 Streams API with various of .NET’s LINQ API capabilities is a very interesting read.

A preview of what you’ll find there (just one of 19 examples):

LINQ

List<string> nameList1 = new List(){ 
  "Anders", "David", "James",
  "Jeff", "Joe", "Erik" };
nameList1.Select(c => "Hello! " + c).ToList()
         .ForEach(c => Console.WriteLine(c));

Java Streams

List<String> nameList1 = asList(
  "Anders", "David", "James",
  "Jeff", "Joe", "Erik");
nameList1.stream()
     .map(c -> "Hello! " + c)
     .forEach(System.out::println);

Read the full blog post here:

http://blog.informatech.cr/2013/03/24/java-streams-preview-vs-net-linq/

Tags: , , , ,

4 responses to “Java Streams Preview vs .Net LINQ”

  1. dejavumaster says :

    The C# code can be replace for the most clear:

    var nameList1 = new List(){ "Anders", "David", "James", "Jeff", "Joe", "Erik" };
    nameList1.Select(c => "Hello! " + c).ToList()
                     .ForEach(Console.WriteLine);
    

    Note that the foreach instruction accepts the method name too

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 2,088 other followers

%d bloggers like this: