Google Guava “zip” two lists

前端 未结 6 2030
萌比男神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:10

    Just pretend this is a Guava method:

    for (int i = 0; i < names.size(); i++) {
        persons.add(new Person(names.get(i), ages.get(i)));
    }
    

提交回复
热议问题