How do you merge indexes of two lists in Groovy? -


i have 2 lists need merge new list, new list needs contain merged indexes of original lists. example:

list1 = [1, 2, 3] list2 = [a, b, c] 

i need output be:

finallist = [1a, 2b, 3c] 

i need able in groovy. appreciate can provide.

assuming both lists same size, in groovy 2.4+,

list1 = [1, 2, 3] list2 = ['a', 'b', 'c']  assert ['1a', '2b', '3c'] == list1.withindex().collect { it, index -> + list2[index] } 

alternatively , bit more in groovy 1.5+,

assert ['1a', '2b', '3c'] == [list1, list2].transpose()*.sum() 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -