22 April 2014

Java8 vs Ruby (Collections)

I feel that the new additions to Java8 will move java forward many steps...

The following is just simple filtering, I just mapping numbers and filter it in both Java8 and Ruby .... Java8 looks pretty much simple as Ruby..

Ruby:
(1..10).to_a.map {|n| n * n}.select {|n| n > 5}.each{|n| puts n}


Java8:
IntStream.rangeClosed(1, 10).map(i -> i * i).filter(i -> i > 5)
                .forEach(i -> System.out.println(i));

Java8 looks very simple... (although the underlying API (stream-api) looks  complex :) )

No comments: