Tuesday, June 25, 2013

Inialize a List in Groovy and Java


I follow the excellent tutorial of  http://groovykoans.org/ and I note that Groovy have a lot of good things that make codes more readable and thinner.

Here is a simple comparaison between Java and Grovvy to initialize a List :

In Java :

        List<String> javaList = new ArrayList<String>();
        javaList.add("King");
        javaList.add("Queen");
        javaList.add("Prince");

In Groovy :

        def groovyList = ['King', 'Prince']


More details on http://groovy.codehaus.org/JN1015-Collections

No comments:

Post a Comment