Take the 2-minute tour ×

I wonder how is this possible in groovy to start an array from the n element.

Look at the snippet :

static void main(args){

    if (args.length < 2){
        println "Not enough parameters"

    def tools = new BoTools(args[0])
    def action = args[1]




As you see am doing here a dynamic method invocation. The first 2 arguments are taken as some config and method name , the others I would like to use as method paramerts. So how can I do something like this :


Edited : If not possilbe in native groovy Java syntax will do it :

def newArgs = Arrays.copyOfRange(args,2,args.length);
share|improve this question
That System.exit(1) is pointless. Java isn't C. –  Esko Mar 18 '12 at 19:28
add comment

1 Answer

up vote 3 down vote accepted

To remove items from the beginning of the args you can use the drop() method. The original args list is not changed:


Other option, like you are trying is to access from N element:

share|improve this answer
+1 for range notation. It is tidy and we already know we have >= 2 values. –  David Mar 18 '12 at 20:40
add comment

Your Answer


