Google Guava “zip” two lists

前端 未结 6 2025
萌比男神i
萌比男神i 2020-12-03 13:34

Using Google Guava (Google Commons), is there a way to merge two equally sized lists into one list, with the new list containing composite objects of the two input lists?

6条回答
  •  暖寄归人
    2020-12-03 14:02

    You can refer to underscore-java library.

    Underscore-java is a port of Underscore.js for Java, and the zip method can achieve the goal.

    Following is a sample code & output :

    $.zip(Arrays.asList("moe", "larry", "curly"), Arrays.asList("30", "40", "50"));
    

    => [[moe, 30], [larry, 40], [curly, 50]]

提交回复
热议问题