Java知识点-判断null、空字符串和空格

                // 判断headerKey是否为null,空字符串或者空格
                if (headerKey != null && headerKey.length() != 0 && headerKey.indexOf(" ") != 0) {
                    List<String> tmp = headers.get(HTTP_HEADER_TO_LOWER_CASE ? headerKey.toLowerCase() : headerKey);
                    if (tmp != null && tmp.size() > 0) {
                        headersToSignMap.put(headerKey, tmp);
                    } else if (headers.containsKey(headerKey)) {
                        headersToSignMap.putSingle(headerKey, "");
                    }
                }

还有可以用 .trim().isEmpty()来判断  空字符串和空格

 

 if (a.trim().isEmpty())
             {
                System.out.println("It is empty");
             }

 

null比较特殊吧?单独判断。

相关文章:

  • 2021-11-04
  • 2021-12-04
  • 2021-12-01
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-12-10
  • 2022-12-23
  • 2021-12-10
  • 2021-12-20
  • 2022-02-25
  • 2022-12-23
  • 2021-11-04
相关资源
相似解决方案