@Test public void zipWithIndexShouldZipEachElementInListWithIndex() { List<String> list = Arrays.asList("first", "second", "third"); List<Pair<Integer, String>> zipped = ListUtils.zipWithIndex(list); assertEquals(list.size(), zipped.size()); for (int i = 0; i < zipped.size(); i++) { assertEquals(i, zipped.get(i).getLeft().intValue()); assertEquals(list.get(i), zipped.get(i).getRight()); } }
public static <X> List<Pair<Integer, X>> zipWithIndex(List<X> list) { return IntStream.range(0, list.size()) .mapToObj(i -> Pair.of(i, list.get(i))) .collect(Collectors.toList()); }
ListUtils { public static <X> List<Pair<Integer, X>> zipWithIndex(List<X> list) { return IntStream.range(0, list.size()) .mapToObj(i -> Pair.of(i, list.get(i))) .collect(Collectors.toList()); } }
ListUtils { public static <X> List<Pair<Integer, X>> zipWithIndex(List<X> list) { return IntStream.range(0, list.size()) .mapToObj(i -> Pair.of(i, list.get(i))) .collect(Collectors.toList()); } private  ListUtils(); }
ListUtils { public static <X> List<Pair<Integer, X>> zipWithIndex(List<X> list) { return IntStream.range(0, list.size()) .mapToObj(i -> Pair.of(i, list.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> List<Pair<Integer, X>> zipWithIndex(List<X> list) { return IntStream.range(0, list.size()) .mapToObj(i -> Pair.of(i, list.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);  }