Comparing two strings for "greater than '0' ..and NULL"

comparison-operators, java, string-comparison

Solution

Assuming you got the price string in a variable price

String price = <get price somehow>;    
try {
    if (price != null && Integer.valueOf(price) > 0) {
        do something with price...
    }
} catch (NumberFormatException exception) {
}

Problem

I am trying to dig my way through the strict Java methods and operators, but now, trying to 'translate' a piece of PHP code to Java (Android), I'm kinda stuck. In PHP: ``` if ($row['price']>'0'){ (.. do something if price is defined - and higher than zero ..) } ``` The problem is that $row['price'] may be empty (in Java: null?) or contain '0' (zero). But how can I code that in Java in a smart and not too complicated way?

Original source