F
Frank Cisco
What's the most efficient way to avoid nulls when getting objects from array
eg.
String eg = array.get("test");
if(eg==null){eg="";} //without this then null pointer gets thrown...
if(!eg.equals("EXAMPLE")){ // ...here
//do something
}
or maybe...
String eg = array.get("test")==null?"":array.get("test"); //neater but 2
lookups with this though
or maybe...
String eg=null;
if((eg=array.get("test"))!=null){
//do stuff
}
I take it the 3rd one is the most efficient?
eg.
String eg = array.get("test");
if(eg==null){eg="";} //without this then null pointer gets thrown...
if(!eg.equals("EXAMPLE")){ // ...here
//do something
}
or maybe...
String eg = array.get("test")==null?"":array.get("test"); //neater but 2
lookups with this though
or maybe...
String eg=null;
if((eg=array.get("test"))!=null){
//do stuff
}
I take it the 3rd one is the most efficient?