Well, I also recently encountered a similar error Type mismatch: cannot convert from Set<Object> to Set<String> . The following is snippet- code:
public static void main(String[] args) { String[] arr = new String[]{"i", "came", "i", "saw", "i", "left"}; Set<String> set = Arrays.asList(arr).stream().collect(Collectors.toSet()); System.out.println(set.size() + " distinct words: " + set); }
Here is a screenshot for reference-: 
Now let me explain why I got this error? In my case, the code displayed a compile-time error, because there was a mismatch in the compiler version in the project properties. I chose 1.7 , but it should be 1.8 , since this feature was added in 1.8 .

Therefore, please write down points- below:
- The appropriate JDK was selected in the Java build path . for example JDK 1.8 in this case.
- The appropriate version of the compiler should be selected in the Java Compiler section (as shown in the screenshot above) in the project properties. e.g. 1.8
I hope this helps you.
source share