开发者

Array of strings in groovy

开发者 https://www.devze.com 2022-12-20 18:53 出处:网络
In ruby, there is a indiom to create a array of strings like this: names = %w( lu开发者_StackOverflow中文版cas Fred Mary )

In ruby, there is a indiom to create a array of strings like this:

names = %w( lu开发者_StackOverflow中文版cas Fred Mary )

Is there something like that in groovy?


If you really want to create an array rather than a list use either

String[] names = ["lucas", "Fred", "Mary"]

or

def names = ["lucas", "Fred", "Mary"].toArray()


Most of the time you would create a list in groovy rather than an array. You could do it like this:

names = ["lucas", "Fred", "Mary"]

Alternately, if you did not want to quote everything like you did in the ruby example, you could do this:

names = "lucas Fred Mary".split()
0

精彩评论

暂无评论...
验证码 换一张
取 消