Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Add item to start of list using Groovy?

Tags:

groovy

How can I use Groovy to add an item to the beginning of a list?

like image 564
Deepti Avatar asked Jun 15 '10 06:06

Deepti


People also ask

How do I add elements to a list in Groovy?

Groovy - add() Append the new value to the end of this List. This method has 2 different variants. boolean add(Object value) − Append the new value to the end of this List.

How do I remove first item from Groovy list?

1 we can use the methods take() and drop() . With the take() method we get items from the beginning of the List. We pass the number of items we want as an argument to the method. To remove items from the beginning of the List we can use the drop() method.

How do I add one list to a list in Groovy?

Combine lists using the plus operator The plus operator will return a new list containing all the elements of the two lists while and the addAll method appends the elements of the second list to the end of the first one. Obviously, the output is the same as the one using addAll method.


1 Answers

list.add(0, myObject); 

You can also read this for some other valuable examples: http://groovy.codehaus.org/JN1015-Collections

like image 149
bezmax Avatar answered Sep 29 '22 05:09

bezmax