Back
I know there is a way for writing a Java if statement in short form.
if (city.getName() != null) { name = city.getName();} else { name="N/A";}
if (city.getName() != null) {
name = city.getName();
} else {
name="N/A";
}
Does anyone know how to write the short form for the above 5 lines into one line?
To avoid calling .getName() twice I would use
name = city.getName();if (name == null) name = "N/A";
if (name == null) name = "N/A";
31k questions
32.8k answers
501 comments
693 users