ric*_*hey 3 java string-comparison comparison-operators
我正在尝试通过严格的Java方法和运算符,但现在,尝试将一段PHP代码"转换"为Java(Android),我有点卡住了.
在PHP中:
if ($row['price']>'0'){
(.. do something if price is defined - and higher than zero ..)
}
Run Code Online (Sandbox Code Playgroud)
问题是$ row ['price']可能为空(在Java中为null?)或包含'0'(零).但是,如何以智能而不是太复杂的方式在Java中编写代码呢?
假设您以可变价格获得价格字符串
String price = <get price somehow>;
try {
if (price != null && Integer.valueOf(price) > 0) {
do something with price...
}
} catch (NumberFormatException exception) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10836 次 |
| 最近记录: |