-1

Can we use logical or operator inside sub condition in Java

if (b.equals("good" || "it was good"))
    System.out.println("Thank goodness");
Federico klez Culloca
  • 24,336
  • 15
  • 57
  • 93
  • I've never heard of something like this, but you could write a method to do it for you with a `String... strings` as required variable so you can list your strings next to each other (`if(equalsOne(myString, "good", "it was good"))`) – Levi Heßmann May 13 '22 at 09:49
  • 2
    No, that's not possible because of the type of the expression. You can use `List.of("good","it was good").contains(b)` – f1sh May 13 '22 at 09:51
  • 2
    Just `b.equals("good") || b.equals("it was good")` or `b.matches("(it was )?good")` – Holger May 13 '22 at 11:03

0 Answers0