Friday, July 20, 2012

Groovy: what difference between array.add and array +

def inX = [0,0]
def inXExpanded = []
(1..2).each {
    inXExpanded += inX
}
println inXExpanded  // the result is [0,0,0,0]

replace the code above to
(1..2).each {
    inXExpanded.add(inX)
}
println inXExpanded  // the result is [[0,0],[0,0]]

No comments:

Post a Comment