Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Created March 15, 2017 21:36
Show Gist options
  • Save animatedlew/e28a0911fdfaea7e9070a4fcd1db78df to your computer and use it in GitHub Desktop.
Save animatedlew/e28a0911fdfaea7e9070a4fcd1db78df to your computer and use it in GitHub Desktop.
package com.company;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Comparison {
// NOT TESTED!!!
static Set<String> diff(String aa, String bb) {
Set<String> cache = new HashSet<>();
Set<String> diff = new HashSet<>();
cache.addAll(Arrays.asList(aa.split(" ")));
for (String b: Arrays.asList(bb.split(" ")))
if (!cache.contains(b)) diff.add(b);
return diff;
}
}
public class Main {
public static void main(String[] args) throws InterruptedException {
Stream<String> xs = Arrays.stream(new String[] {"abc", "bce", "fghi", "jklm", "opqr", "tuvw", "vwxyz", "opmano", "tuvwx" });
Stream<String> ys = Arrays.stream(new String[] {"abc", "bc", "fg", "jkl", "opqr", "tuvw", "vwxyz" });
List<String> yss = ys.limit(1000).collect(Collectors.toList());
xs
.flatMap(x -> yss.stream().map(y -> "(" + x + ", " + y + ") diff:" + Comparison.diff(x, y)))
.forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment