I am trying to assign a default value to variable if the variable holds an empty string. I used the following codes but they are not working out:
if (d.lat.trim().isEmpty())
latt = 9.0819990;
else {
latt = Double.valueOf(d.lat.trim()).doubleValue();
}
The above code results in an error:
cannot find symbol
symbol : method isEmpty()
location: class java.lang.String
then I used
if (" ".equals(d.lat.trim()))
latt = 9.0819990;
else {
latt = Double.valueOf(d.lat.trim()).doubleValue();
}
The code above jumps the if section and tries to convert the empty String into double thereby throwing error about empty string.
SO, what am I doing wrong?
The empty string is
"", not" "(note that there is no space between the quotes).