且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Groovy:将列表的某些元素添加到另一个列表

更新时间:2023-02-01 17:20:30

[list1, list2].transpose()*.flatten()

假设list1list2的基数相同.

更新
现在已经大大地修改了问题,但是可以通过如下扩展移调来获得想要的结果:

UPDATE
Question is modified drastically now, but you can get what you seek by extending the transpose as below:

[list1, list2].transpose()*.flatten()
                           .collect{[it[0], it[-2..-1], it[1..-3]]}*.flatten()