@Test public void zipShouldZipLists() { List<String> left = Arrays.asList("left 1", "left 2", "left 3"); List<String> right = Arrays.asList("right 1", "right 2", "right 3"); List<Pair<String, String>> zipped = ListUtils.zip(left, right); assertEquals(left.size(), zipped.size()); assertEquals(right.size(), zipped.size()); for (int i = 0; i < zipped.size(); i++) { assertEquals(left.get(i), zipped.get(i).getLeft()); assertEquals(right.get(i), zipped.get(i).getRight()); } }
public static <X, Y> List<Pair<X, Y>> zip(List<X> left, List<Y> right) { if (left.size() != right.size()) { throw new IllegalArgumentException(String.format("List sizes do not match: left=%d, right=%d", left.size(), right.size())); } return IntStream.range(0, left.size()) .mapToObj(i -> Pair.of(left.get(i), right.get(i))) .collect(Collectors.toList()); }
ListUtils { public static <X, Y> List<Pair<X, Y>> zip(List<X> left, List<Y> right) { if (left.size() != right.size()) { throw new IllegalArgumentException(String.format("List sizes do not match: left=%d, right=%d", left.size(), right.size())); } return IntStream.range(0, left.size()) .mapToObj(i -> Pair.of(left.get(i), right.get(i))) .collect(Collectors.toList()); } }
ListUtils { public static <X, Y> List<Pair<X, Y>> zip(List<X> left, List<Y> right) { if (left.size() != right.size()) { throw new IllegalArgumentException(String.format("List sizes do not match: left=%d, right=%d", left.size(), right.size())); } return IntStream.range(0, left.size()) .mapToObj(i -> Pair.of(left.get(i), right.get(i))) .collect(Collectors.toList()); } private  ListUtils(); }
ListUtils { public static <X, Y> List<Pair<X, Y>> zip(List<X> left, List<Y> right) { if (left.size() != right.size()) { throw new IllegalArgumentException(String.format("List sizes do not match: left=%d, right=%d", left.size(), right.size())); } return IntStream.range(0, left.size()) .mapToObj(i -> Pair.of(left.get(i), right.get(i))) .collect(Collectors.toList()); } private  ListUtils(); static List<Pair<X, Y>> zip(List<X> left, List<Y> right); static List<Pair<Integer, X>> zipWithIndex(List<X> list); }
ListUtils { public static <X, Y> List<Pair<X, Y>> zip(List<X> left, List<Y> right) { if (left.size() != right.size()) { throw new IllegalArgumentException(String.format("List sizes do not match: left=%d, right=%d", left.size(), right.size())); } return IntStream.range(0, left.size()) .mapToObj(i -> Pair.of(left.get(i), right.get(i))) .collect(Collectors.toList()); } private  ListUtils(); static List<Pair<X, Y>> zip(List<X> left, List<Y> right); static List<Pair<Integer, X>> zipWithIndex(List<X> list);  }