The question is simple and can be done in thousand of ways. But since I am learning Java 8, I would like to do it in the Java 8 way.
I have two list of strings, ex:
List<String> list1 = Arrays.asList("A", "B", "C", "D");
List<String> list2 = Arrays.asList("A", "D", "E");
I want to take the first element from list1 and check if the string is present in list2 and produce a Map<Boolean, String>. Something like this:
Map<Boolean, String> resultMap = list1.stream().collect(partial -> Collectors.partitioningBy(list2.stream().filter(existing -> matchString(partial, existing))));
private static boolean matchString(String partial, String existing) {
return partial.equals(existing);
}
The above code has a compilation error at matchString(partial, existing):
Wrong 1st argument type. Found: '', required: 'java.lang.String'
Few things to note is that, the in my actual scenario it's not a simple list of string but a more complicated object and that object doesn't override equals or hashcode method.
I very well know that this can be done in different ways. But could somebody please let me know how do we use Collectors.partitioningBy in this particular scenario.

Map<Boolean, String>represents. All we have is a snippet of code that doesn't compile.