Java List Zip zip(final List l1, final List l2)

Here you can find the source of zip(final List l1, final List l2)

Description

Zips 2 lists together.

License

Open Source License

Parameter

Parameter Description
Element type used in the list
l1 first list, merged at uneven positions
l2 second list, merged at even positions

Return

zipped list

Declaration

public static <Element> List<Element> zip(final List<Element> l1, final List<Element> l2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.List;

public class Main {
    /**/*from  w w  w .j  a v  a  2s  . co  m*/
     * Zips 2 lists together.
     * @param <Element> type used in the list
     * @param l1 first list, merged at uneven positions
     * @param l2 second list, merged at even positions
     * @return zipped list
     */
    public static <Element> List<Element> zip(final List<Element> l1, final List<Element> l2) {
        ArrayList<Element> result = new ArrayList<Element>();
        for (int i = 0; i < l1.size(); i++) {
            result.add(l1.get(i));
            result.add(l2.get(i));
        }
        return result;
    }
}

Related

  1. zip(List a, List b)
  2. zip(List> lists)
  3. zip(List> lists)
  4. zipDoubleArray(List lists)