简体   繁体   English

如何在 Java 中打印 if 执行条件检查

[英]How print the if executed condition check in Java

How can i check for which condition inside if StringUtils.isBlank() returned true and executed the if condition how can i print that check condition at this if got success is it because of age or name or whatever如果 StringUtils.isBlank() 返回 true 并执行 if 条件,我如何检查其中的哪个条件

public boolean validating(){
if(StringUtils.isBlank(age) || StringUtils.isBlank(name) || StringUtils.isBlank(status) || StringUtils.isBlank(location){ return false;}
else{
return true;}
}

You can make a boolean equivalent for each checks for age, name, status, and location as a workaround.您可以使 boolean 等效于每次检查年龄、姓名、状态和位置作为解决方法。

    boolean isAgeBlank = StringUtils.isBlank(age);
    boolean isNameBlank = StringUtils.isBlank(name);
    boolean isStatusBlank = StringUtils.isBlank(status);
    boolean isLocationBlank = StringUtils.isBlank(location);
    if(isAgeBlank || isNameBlank || isStatusBlank || isLocationBlank){
        //do whatever you want in each case
        if(!isAgeBlank) System.out.println("Age provided!"); //do the rest
        return true;
    }else{
        return false;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM