if (boozeAmount == "" || boozeAmount == null){
It can be easily deduced from your explanation that this particular if
statement is returning true
, that's why your string value is not being set to "0".
Strings in Java are not primitive, i.e they cannot be compared with the comparator ==
.
You need to use the method equals
to compare strings, as in boozeAmount.equals("")
.
Apache Commons has a StringUtils utility that can check if strings are null or empty.
Check out isEmpty
and isBlank
.