Reputation: 5055
I'm learning Groovy. I want an array of numbers from 0 to n with interval 0.1.
double arr=[0,0.1,0.2....n]
I could write a java style for-loop, but is there a easier syntax to do this? I know Groovy has a lot of syntactic sugar.
Upvotes: 5
Views: 7107
Reputation: 175
there was an exact question here earlier
n=10;(0..10*n).collect{it/10}
there are no decimal step values for Groovy's ranges currently
Upvotes: -1
Reputation: 133569
I would go with 0.0..10.0.collect{it/10.0}
but maybe there is clever way to do it by specifying increments.
Upvotes: 8