else if (select! = ("1" | "2" | "3"))

select, "1", "2" and "3" are of type String, so! = does not fit

  • one
    opposite equals (), I dare to suggest:! equals () - Artem -.... .- ....-.-
  • Thanks, but this does not exist - Denis Korolenko
  • one
    I'm talking about:! string.equals (string) - Artem -.... .- ....-.-
  • in the nine - !Set.of( "1", "2", "3" ).contains( select ) . In earlier versions, instead of Set.of you can use Arrays.asList - zRrr

2 answers 2

 else if (!select.equals("1")||!select.equals("2")||!select.equals("3")) 
  • one
    This expression will always return true for any select! = Null - Andrey Dorohovich 2:42 pm

Strings other than "1", "2" or "3" can also be null . And if it turns out that the select string is null , then when checking the proposed @Tsyklop you will get a NullPointerException. Correctly check this: if(!"1".equals(select)&&!"2".equals(select)&&!"3".equals(select))

those. for any select value other than "1", "2" and "3" will be true .