Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a collection/array in size N with each cell initialized to zero in Groovy?

Tags:

groovy

Is there a short way to create a collection/array in size N with each cell initialized to zero in Groovy? Can't seem to find it on http://groovy.codehaus.org/JN1015-Collections

For example

arr = func(3)  

would result in

arr = [0, 0, 0]
like image 627
user971956 Avatar asked Dec 12 '12 14:12

user971956


Video Answer


1 Answers

Yep, the Collection#multiply (or *) method:

assert [0] * 3 == [0, 0, 0]
like image 98
epidemian Avatar answered Oct 14 '22 07:10

epidemian