Is there any way I can compare values like this?
if (ci.getNumber() == (6252001|5855797|6251999)) { ... }
Is there any way I can compare values like this?
if (ci.getNumber() == (6252001|5855797|6251999)) { ... }
You could put all the numbers in a collection, and then use the contains()
method. Other than that, I don't believe there is any special syntax for comparing like you want to do.
No, you're going to need to check ci.getNumber() == ...
for each value, or add them to a collection and check myCollection.contains(ci.getNumber())
. However, you may want to re-think the structure of your code if you are checking a method against several known values.
Java won't let you do that. You can do a hash lookup (which is overkill for this) or a case statement, or a big honking ugly multiple compare:
if ((n==1 ) || (n==2) || ...
using the answer from:
you could create an array of numbers and check if your ci.getNumber() is in it.
There is no such operator. But if you are comparing number, you can use switch do simulate that. Here is how:
int aNumber = ci.getNumber();
swithc(aNumber) {
case 6252001:
case 5855797:
case 6251999: {
...
break;
}
default: {
... // Do else.
}
}
Hope this helps.
No. You could create a Set<Integer>
once and then use that, or just:
int number = ci.getNumber();
if (number == 6252001 || number == 5855797 || number == 6251999)
I'd also consider changing those numbers into constants so that you get more meaningful code.