zoukankan      html  css  js  c++  java
  • java处理字符串-判断是否为空

    判断字符串是否为空:

    1)最多人使用的一个方法, 直观, 方便, 但效率很低;

     if (str == null || "".equals(str)) {
      }

    2)比较字符串长度, 效率高, 是最好的一个方法;

    if (str == null || str.length() <= 0) {
       }

    3)Java SE 6.0 才开始提供的方法, 效率和方法二几乎相等, 但出于兼容性考虑, 推荐使用方法二;

    if (str == null || str.isEmpty()) {
     
       }

    4)这是一种比较直观,简便的方法,而且效率也非常的高,与方法二、三的效率差不多;

     if (str == null || str == "") {
    
         }

    5) 使用JDK提供的工具类

    boolean  isNullOrEmpty=StringUtils.isBlank(str)

    参考博客:判断字符串String是否为空问题

  • 相关阅读:
    Splash wait() 方法
    Splash go() 方法
    Splash 对象方法
    短信接口文档
    WMS开发环境
    Eureka
    pom.xml settings.xml
    Druid
    EAI并发
    重启WMS服务
  • 原文地址:https://www.cnblogs.com/Tpf386/p/14146830.html
Copyright © 2011-2022 走看看