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/

4 thoughts on “Java Streams Preview vs .Net LINQ

  1. 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