Through Scanner enter any text, it turns out the line:

 Scanner reader = new Scanner(System.in); String number = reader.nextLine(); 

There is also a collection with results:

 Set<String> result = new HashSet<>(); 

It is necessary to check, by entering text, whether there is an input value in the collection.
Under the condition if (number.equals(result)) - the types are different, therefore it does not compare.

How can you compare?

  • How to compare a basket of apples with an apple? The question is incorrect - Mikhail Ionkin

1 answer 1

To check the presence of an element in the Set there is a contains method:

 if (result.contains(number)) 
  • Thus, any element entered will be true, regardless of what is in the collection. - Hektor Fektor
  • @HektorFektor why? If only the strings "aaa" and "bbb" are stored in result and the number is "ccc" , then the contains will return false . - Regent
  • Found a mistake, thanks for the reply. - Hektor Fektor
  • @HektorFektor on health. If you are satisfied with the answer, do not forget to mark it as appropriate (checkmark to the left of the answer). - Regent