I was wondering, do you have a neat way of doing this ?
if(orderBean.getFiles().size() > 0 && orderBean.getFiles().size() < 5)
without declaring a variable that is not needed anywhere else ?
int filesCount = orderBean.getFiles().size();
if(filesCount > 0 && filesCount < 5) {
I mean, in for loop we are "declaring conditions" for the actual iteration, one can declare a variable and then specify the conditions. Here one can't do it, and neither can do something like
if(5 > orderBean.getFiles().size() > 0)
When a number is bigger than or smaller than another number, greater than less than symbols are used. If the first number is greater than the second number, greater than symbol (>) is used. If the first number is less than the second number, less than symbol (<) is used.
Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is not true. Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is true.
Another way to remember the greater than and less than signs is something that you may remember from grade school: the Alligator Method. Imagine the symbols as an alligator mouth with the numbers on each side being little fish. The alligator will always want to eat a larger number of fish.
Simple utility method:
public static boolean isBetween(int value, int min, int max)
{
return((value > min) && (value < max));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With