48

I've got two List objects and I want to pair them up, just like the zip() function in Python. I'm pretty sure this isn't available in the JDK, but is there something like this in a fairly widespread library, similar to Apache Commons Collections? Thanks.

Hank Gay
  • 70,339
  • 36
  • 160
  • 222
  • Not well versed in Python and how zip is used but a Quick glance makes me thing that ListUtils from the Collections library should do the trick. combinedList = ListUtils.union(list1, list2) ; Iterate over the combined list. https://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/ListUtils.html#union(java.util.List,%20java.util.List) – trappski Nov 02 '16 at 10:03
  • @trappski, that's just a wrapper for List.addAll which does not solve the problem. – micseydel Jun 28 '17 at 16:18

1 Answers1

24

Functional Java has zip, zipWith and zipIndex the way you would expect from Haskell or Scala. (Indeed, the authors are pretty much all Haskell programmers.)

Community
  • 1
  • 1
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653