java 条件判断

Last updated on November 22, 2024 pm

🧙 Questions

☄️ Ideas

Strings判断
// 对null和"" 为true,其余都是false,注意 " "是有字符的
// org.apache.logging.log4j.util.Strings Strings.isNotEmpty("");
System.out.printf(String.valueOf(Strings.isEmpty(null)));
System.out.printf(String.valueOf(Strings.isEmpty("")));
System.out.printf(String.valueOf(Strings.isEmpty(" ")));
System.out.printf(String.valueOf(Strings.isEmpty("ispong")));
System.out.printf(String.valueOf(Strings.isEmpty(" ispong ")));

// 类似Strings.isEmpty(),推荐使用spring自家的StringUtils.hasLength()
System.out.printf(String.valueOf(StringUtils.hasLength(null)));
System.out.printf(String.valueOf(StringUtils.hasLength("")));
System.out.printf(String.valueOf(StringUtils.hasLength(" ")));
System.out.printf(String.valueOf(StringUtils.hasLength("ispong")));
System.out.printf(String.valueOf(StringUtils.hasLength(" ispong ")));

// 对于null,"","  "为true,其余都是false,空字符串不算字符串
// Strings.isNotBlank("");
System.out.printf(String.valueOf(Strings.isBlank(null)));
System.out.printf(String.valueOf(Strings.isBlank("")));
System.out.printf(String.valueOf(Strings.isBlank(" ")));
System.out.printf(String.valueOf(Strings.isBlank("ispong")));
System.out.printf(String.valueOf(Strings.isBlank(" ispong ")));

// 类似Strings.isNotBlank(),推荐使用spring自家的StringUtils.hasText()
System.out.printf(String.valueOf(StringUtils.hasText(null)));
System.out.printf(String.valueOf(StringUtils.hasText("")));
System.out.printf(String.valueOf(StringUtils.hasText(" ")));
System.out.printf(String.valueOf(StringUtils.hasText("ispong")));
System.out.printf(String.valueOf(StringUtils.hasText(" ispong ")));ƒ

java 条件判断
https://ispong.isxcode.com/spring/java/java 条件判断/
Author
ispong
Posted on
December 7, 2023
Licensed under