23 April 2014

Java8 vs Ruby (Files)

We talked about the the syntax similarities between Ruby and Java8 when dealing with collections in last post.

In this post, we will talk about manipulating files, specially reading files contents.

To read content of File:

In Ruby:
f=File.open "/bin/which"
f.each{|line| puts line}

In Java:
Stream<String> lines = Files.lines(Paths.get("/bin/which"));
lines.forEach(line -> System.out.println(line));

Very Similar!, Viva Java8
Post a Comment