Java 8 StreamZipper

The code (it’s a single class) is on pastebin:

This code is from an early build of Java 8 Beta. This was removed later and no zip function exists in the final Java 8 release. Here’s the source I used:
changeset 8789:569088178418.

There’s also a Discussion on Stackoverflow.

I added a very simple “Pair” class. You can just as well remove it and use javatuples instead.

And here’s some Example code:

// ...
public static void main(String[] args) { 
  Stream<Integer> a = IntStream.of(1, 2, 3).boxed();  
  Stream<String> b = Stream.of("a", "b", "c");  
  Stream<Pair<Integer, String>> zipped
     =, b, Pair<Integer, String>::new);  
  // Output:
  // [Pair(1, a), Pair(2, b), Pair(3, c)]}

Leave a Reply

Your email address will not be published. Required fields are marked *