Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: egarrulo Newsgroups: comp.lang.java.programmer Subject: Re: Libraries for sysadmins? Date: Fri, 4 Mar 2016 20:30:17 +0100 Lines: 52 Message-ID: References: <2cec6af2-9636-4a2a-8849-b01286c0814c@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net 20LWNP1V4Z6NdIhSxisweQtx0QrEWQIKD0iP4vpLibCBHiCzmK Cancel-Lock: sha1:Bt97RDo2KSQKh0w3Qu8XDGWrI3U= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:33923 On 04/03/16 18:06, Robert Klemme wrote: > > I would look into using JRuby, maybe also look into Groovy (not sure how > much alive the latter is these days). > > On 04.03.2016 16:13, Stefan Ram wrote: >> Elena writes: >>> processing text files line by line >> >> Writing lines to a text file: >> >> new java.io.FileWriter( "c:\\example.txt" ). >> append( "alpha\n" ).close(); > > In (J)Ruby: > > File.open("example.txt", "a") {|io| io.puts "alpha"} > >> Reading a text file line by line (not tested): >> >> final java.util.Scanner scanner >> = new java.util.Scanner( new java.io.File( "file.txt" )); >> while( scanner.hasNextLine() ) >> { final java.lang.String line = scanner.nextLine(); > > In (J)Ruby: > > File.foreach "file.txt" do |line| > # whatever > end > >>> filtering collections >> >> (not tested): >> >> java.util.Arrays.asList( 1, 2, 3 ).stream(). >> filter( x -> "x >= 2 ) > > Again, in (J)Ruby: > > [1,2,3].select {|x| x >= 2} > > (Not exactly the same, but can easily be made to if need be.) > > Kind regards > > robert Wow! The Java version is remarkably concise and compares favourably with the Ruby version. Where could I find more of these examples of "short and sweet" Java? In the "Java Cookbook" (3rd edition) by Ian F. Darwin, maybe?