(Predicate<? super String> s) or (String s)

There is no need to use a Predicate here. In order to check if the String is present in your TreeSet just use :

return systemLabels.contains("Person");

If you still insist on using anyMatch then you can do :

public static boolean validateSystemLabel(String s) {
    return systemLabels.stream().anyMatch(i -> i.equals(s));
}

Remember, a predicate expression needs to evaluate to a boolean value but in the code, you are passing in a String hence the compilation error.


The problem in your solution is this line:

SystemLabels.stream().anyMatch(j);

Basically anyMatch() expects Predicate as input not String.

But your problem has simpler solution:

import java.util.Set;
import java.util.TreeSet;

public class SystemLabelValidator {

    private static final Set<String> SYSTEM_LABLES = new TreeSet<>(Arrays.asList("Person", "Player", "Hospital", "Nurse", "Room"));

    public static boolean validateSystemLabel( String value) {  
        return SYSTEM_LABLES.contains(value);
    }

}