简体   繁体   中英

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

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 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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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