Reputation: 1370
Lets say I have list of values..
List values = [["A","A"],["B","B"],["C","C"],["D","D"]]
and I would like to push a value, "*", into the list so it looks like this
[["*", "A","A"],["*", "B","B"],["*", "C","C"],["*", "D","D"]]
Any ideas how to do this?
Thanks!
Upvotes: 0
Views: 178
Reputation: 312
The star-dot method may help. It would look like this:
values*.addAll(0, "*")
The docs could use some improvement here. :)
http://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/Collection.html
Upvotes: 2
Reputation: 1370
For anyone interested,
this seem to work:
List values = [["A","A"],["B","B"],["C","C"],["D","D"]]
values.each{
it.addAll(0,"*")
}
println values
OUTPUT
[[*, A, A], [*, B, B], [*, C, C], [*, D, D]]
Upvotes: 0