I have a POJO class.
class Activity{
private String name;
public String getName()
return name;
}
public void setName(String name){
this.name=name;
}
}
im having belw condtions.its not enr=ering properly in those condtions accordingly
if(stlmtTransRequestVO.getStlmtTransId()!=null && stlmtTransRequestVO.getPaymentTransId()!=null){
stlmtTransDtlsList = (List<StlmtTransResponseVO>) queryForList(
"GET_STLMTPAY_TRANSACTIONS", stlmtTransRequestVO);
}else if(stlmtTransRequestVO.getAgentId()!=null && stlmtTransRequestVO.getAgencyId()==null){
stlmtTransDtlsList = (List<StlmtTransResponseVO>) queryForList(
"GET_AGENT_TRANSACTIONS", stlmtTransRequestVO);
}else if(stlmtTransRequestVO.getAgencyId()!=null && stlmtTransRequestVO.getAgentId()==null){
stlmtTransDtlsList = (List<StlmtTransResponseVO>) queryForList(
"GET_AGENCY_TRANSACTIONS", stlmtTransRequestVO);
}else if(stlmtTransRequestVO.getAgencyId()!=null && stlmtTransRequestVO.getAgentId()!=null){
}
How to check this getter method for having data or not?
I have tried below scenarios but not working
1) obj.getName()!=null
2) obj.getName().isEmpty()
In order to check whether a Java object is Null or not, we can either use the isNull() method of the Objects class or comparison operator.
Use "==" to check a variable's value. If you set a variable to null with "=" then checking that the variable is equal to null would return true.
obj.getName() != null
is right. But it depends on your definition of "having data". It might be: object.getName() != null && !obj.getName().isEmpty()
.
There are utilities to facilitate that, like apache commons-lang StringUtils.isNotEmpty(..)
if( obj.getName() != null && !"".equals(obj.getName()) ){
//getName is valid
}
Above is checking that name is not null and also it's not empty. Also "".equals(obj.getName()) is considered better approach than obj.getName().equals("").
Initialize like this:
private String name = "";
Then you can check it with:
obj.getName().isEmpty();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With