Reputation: 19
Trying to check a password against values in a hash set. The error appears to be in the myset.contains but cant see why.
Set<String> myset = new HashSet<>();
myset.add("Apples");
myset.add("Bananas");
String inputPass;
Scanner input = new Scanner(System.in);
System.out.println("Fruit?: ");
inputPass = input.nextLine();
if (inputPass.equals(myset.contains)) {
// Lecturer.printMe();
System.out.println("Welcome");
}
else {
System.out.println("ACCESS DENIED");
}
Would appreciate some guidance.
Upvotes: 0
Views: 38
Reputation: 81
"contains" is a method, not a field. Also, it accepts an instance of T (in this case, a String) as a parameter.
Upvotes: 1
Reputation: 522506
You use of Set#contains
does not look right to me. Try using this version:
if (myset.contains(inputPass)) {
System.out.println("Welcome");
}
else {
System.out.println("ACCESS DENIED");
}
Upvotes: 0