Is it possible to use 'or' operator multiple times without getting an error in java
if(var=="20"|"22"|"24"....)) | is bitwise OR operator. You need to use ||
Syntax should be something like below for your requirement
if(var.equals("20")|| var.equals("22")|| var.equals("24")) 20|22|24 would be disastrous.| is both bitwuse or and the non-short circuiting logical OR operator|| is NOT required here! I could code it with | and it would workLots of problems here.
First, you can't compare strings using ==, which tests if the 2 operands are the same object. Use equals():
if (var.equals("21")) Next, you can't group up operands like that, you must use separate calls to equals(), but instead of that you can also do this:
if (Arrays.asList("20", "22", "24", ....).contains(var)) I guess you are looking for the switch statement (works with strings too, since Java 7). Using or is not what you want in my opinion. Example:
switch (var) { case "20"://document fall-through to prevent future changes case "22"://no break here either case "24": //do what you want. break; }