package aa;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
public class AADemo_4 {
public static void main(String[] args) {
User1 user1 = new User1("xiaowang",17);
User1 user11 = null;
System.out.println(user1.toString());
try{
System.out.println(user11.toString());
}catch (NullPointerException e){
e.printStackTrace();
}
System.out.println(String.valueOf(user1));
System.out.println(String.valueOf(user11) == "null");
System.out.println(StringUtils.isBlank(String.valueOf(user11)));
System.out.println(StringUtils.isEmpty(String.valueOf(user11)));
System.out.println(StringUtils.isBlank(" "));
System.out.println(StringUtils.isEmpty(" "));
System.out.println(Objects.toString(user11, null));
}
static class User1{
String name;
Integer age;
public User1(String name, Integer age) {
this.name = name;
this.age = age;
}
@Override
public String toString() {
return "User1{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
}
|