amountStr
is a value that occasionally contains a double value represented as a string.
I want to use Double.parseDouble
to read it into a double
variable: amountDbl
.
this.amountDbl = Double.parseDouble(amountStr);
It seems to throw a NullPointerException
if amountStr
doesn't have a value.
Does this mean I have to write a check like this every time?
if(amountStr!=null)
this.amountDbl = Double.parseDouble(amountStr);
Because I have so many statements like this in my code, I'm hoping for a more concise way of doing this check (or avoiding it).