Create comma separated string from 2 lists the groovy way

Posted by Micor on Stack Overflow See other posts from Stack Overflow or by Micor
Published on 2011-01-14T00:20:02Z Indexed on 2011/01/14 3:53 UTC
Read the original article Hit count: 196

Filed under:

What I have so far is:

def imageColumns = ["products_image", "procuts_subimage1", "products_subimage2", "prodcuts_subimage3", "products_subimage4"]    
def imageValues = ["1.jpg","2.jpg","3.jpg"]
def imageColumnsValues = []

// only care for columns with values
imageValues.eachWithIndex { image,i ->
  imageColumnsValues <<  "${imageColumns[i]} = '${image}'"
}

println  imageColumnValuePair.join(", ") 

It works but I think it could be better. Wish there was a collectWithIndex ... Any suggestions?

© Stack Overflow or respective owner

Related posts about groovy