I\'m a newbie Java coder and I just read a variable of an integer class can be described three different ways in the API. I have the following code:
if (count.
Although you could certainly use the compareTo
method on an Integer instance, it's not clear when reading the code, so you should probably avoid doing so.
Java allows you to use autoboxing (see http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html) to compare directly with an int, so you can do:
if (count > 0) { }
And the Integer
instance count
gets automatically converted to an int
for the comparison.
If you're having trouble understanding this, check out the link above, or imagine it's doing this:
if (count.intValue() > 0) { }