What's the cleanest way to sequentially attempt to assign a variable from a dataset, moving to the following if the former returns null or is empty? I'm working in Java.
Pseudo code:
I know .contains exists for maps; the real code I'm working with isn't a map, but this should give a decent illustration.
Object variable = firstmap.get(key);
if (variable == null) {
variable = secondmap.get(key);
if (variable == null) {
variable = thirdmap.get(key);
if (variable == null) {
...
}
}
}
I could break this up like this, sure, but it still doesn't seem great:
Object variable = firstmap.get(key);
if (variable == null) {
variable = secondmap.get(key);
}
if (variable == null) {
variable = thirdmap.get(key);
}
if (variable == null) {
...
}
...
Is there a cleaner way? Having a true brain burp.