Skip to content

Instantly share code, notes, and snippets.

@m4tx
Created May 8, 2017 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4tx/ca0958cf1fea21b55bae600a72eb58d3 to your computer and use it in GitHub Desktop.
Save m4tx/ca0958cf1fea21b55bae600a72eb58d3 to your computer and use it in GitHub Desktop.
package utils;
import scala.Tuple2;
import scala.collection.JavaConversions;
import scala.collection.Seq;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
public class ScalaConverters {
public static <A, B> Seq<Tuple2<A, B>> mapToEntrySeq(Map<A, B> map) {
Set<Tuple2<A, B>> set = map
.entrySet()
.stream()
.map(x -> new Tuple2<>(x.getKey(), x.getValue()))
.collect(Collectors.toSet());
return JavaConversions.asScalaSet(set).toSeq();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment