当前位置: 首页 > news >正文

代码中 isEmpty 和 isBlank 的区别

isEmpty系列
StringUtils.isEmpty()
是否为空. 可以看到 " " 空格是会绕过这种空判断,因为是一个空格,并不是严格的空值,会导致 isEmpty(" ")=false

tringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty(“bob”) = false
StringUtils.isEmpty(" bob ") = false
/** <p>NOTE: This method changed in Lang version 2.0.* It no longer trims the CharSequence.* That functionality is available in isBlank().</p>** @param cs  the CharSequence to check, may be null* @return {@code true} if the CharSequence is empty or null* @since 3.0 Changed signature from isEmpty(String) to isEmpty(CharSequence)*/
public static boolean isEmpty(final CharSequence cs) {return cs == null || cs.length() == 0;
}

StringUtils.isNotEmpty()
相当于不为空 , = !isEmpty()

public static boolean isNotEmpty(final CharSequence cs) {return !isEmpty(cs);}

StringUtils.isAnyEmpty()
是否有一个为空,只有一个为空,就为true.

StringUtils.isAnyEmpty(null) = true
StringUtils.isAnyEmpty(null, “foo”) = true
StringUtils.isAnyEmpty("", “bar”) = true
StringUtils.isAnyEmpty(“bob”, “”) = true
StringUtils.isAnyEmpty(" bob ", null) = true
StringUtils.isAnyEmpty(" ", “bar”) = false
StringUtils.isAnyEmpty(“foo”, “bar”) = false
/* @param css  the CharSequences to check, may be null or empty* @return {@code true} if any of the CharSequences are empty or null* @since 3.2*/
public static boolean isAnyEmpty(final CharSequence... css) {if (ArrayUtils.isEmpty(css)) {return true;}for (final CharSequence cs : css){if (isEmpty(cs)) {return true;}}return false;
}

StringUtils.isNoneEmpty()
相当于!isAnyEmpty(css) , 必须所有的值都不为空才返回true

/* <p>Checks if none of the CharSequences are empty ("") or null.</p>** <pre>* StringUtils.isNoneEmpty(null)             = false* StringUtils.isNoneEmpty(null, "foo")      = false* StringUtils.isNoneEmpty("", "bar")        = false* StringUtils.isNoneEmpty("bob", "")        = false* StringUtils.isNoneEmpty("  bob  ", null)  = false* StringUtils.isNoneEmpty(" ", "bar")       = true* StringUtils.isNoneEmpty("foo", "bar")     = true* </pre>** @param css  the CharSequences to check, may be null or empty* @return {@code true} if none of the CharSequences are empty or null* @since 3.2*/
public static boolean isNoneEmpty(final CharSequence... css) {

isBank系列
StringUtils.isBlank()
是否为真空值(空格或者空值)

StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank(“bob”) = false
StringUtils.isBlank(" bob ") = false
/* <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>* @param cs  the CharSequence to check, may be null* @return {@code true} if the CharSequence is null, empty or whitespace* @since 2.0* @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)*/
public static boolean isBlank(final CharSequence cs) {int strLen;if (cs == null || (strLen = cs.length()) == 0) {return true;}for (int i = 0; i < strLen; i++) {if (Character.isWhitespace(cs.charAt(i)) == false) {return false;}}return true;
}

StringUtils.isNotBlank()
是否真的不为空,不是空格或者空值 ,相当于!isBlank();

public static boolean isNotBlank(final CharSequence cs) {return !isBlank(cs);}

StringUtils.isAnyBlank()
是否包含任何真空值(包含空格或空值)

StringUtils.isAnyBlank(null) = true
StringUtils.isAnyBlank(null, “foo”) = true
StringUtils.isAnyBlank(null, null) = true
StringUtils.isAnyBlank("", “bar”) = true
StringUtils.isAnyBlank(“bob”, “”) = true
StringUtils.isAnyBlank(" bob ", null) = true
StringUtils.isAnyBlank(" ", “bar”) = true
StringUtils.isAnyBlank(“foo”, “bar”) = false
 /* <p>Checks if any one of the CharSequences are blank ("") or null and not whitespace only..</p>* @param css  the CharSequences to check, may be null or empty* @return {@code true} if any of the CharSequences are blank or null or whitespace only* @since 3.2*/
public static boolean isAnyBlank(final CharSequence... css) {if (ArrayUtils.isEmpty(css)) {return true;}for (final CharSequence cs : css){if (isBlank(cs)) {return true;}}return false;
}

StringUtils.isNoneBlank()
是否全部都不包含空值或空格

StringUtils.isNoneBlank(null) = false
StringUtils.isNoneBlank(null, “foo”) = false
StringUtils.isNoneBlank(null, null) = false
StringUtils.isNoneBlank("", “bar”) = false
StringUtils.isNoneBlank(“bob”, “”) = false
StringUtils.isNoneBlank(" bob ", null) = false
StringUtils.isNoneBlank(" ", “bar”) = false
StringUtils.isNoneBlank(“foo”, “bar”) = true
/* <p>Checks if none of the CharSequences are blank ("") or null and whitespace only..</p>* @param css  the CharSequences to check, may be null or empty* @return {@code true} if none of the CharSequences are blank or null or whitespace only* @since 3.2*/
public static boolean isNoneBlank(final CharSequence... css) {return !isAnyBlank(css);
}

相关文章:

代码中 isEmpty 和 isBlank 的区别

isEmpty系列 StringUtils.isEmpty() 是否为空. 可以看到 " " 空格是会绕过这种空判断,因为是一个空格,并不是严格的空值,会导致 isEmpty(" ")false tringUtils.isEmpty(null) true StringUtils.isEmpty("") true StringUtils.isEmpty(" …...

为什么要选择文件传输软件?有哪些最佳高速文件传输软件?

是否经历过这样的场景&#xff0c;正在努力地完成工作任务&#xff0c;但是由于制作的数据无法及时传送给合作伙伴&#xff0c;工作流程被打断了&#xff1f;这听起来很令人沮丧&#xff0c;对吧&#xff1f;可是&#xff0c;这种情况在现实中并不罕见。 因此&#xff0c;需要…...

aardio + customPlus 显示图片演示

看效果&#xff1a; 上代码&#xff1a; import win.ui; /*DSG{{*/ var winform win.form(text"aardio customPlus 显示图片演示 by 光庆";right927;bottom607) winform.add( button{cls"button";text"下一页";left664;top536;right794;bott…...

收集到大量的名片怎么转为excel?

来百度APP畅享高清图片 参加完展会或集体会议&#xff0c;是不是收了一大堆名片&#xff0c;保管起来超级麻烦&#xff0c;还容易丢三落四&#xff1f;别急&#xff0c;我们有办法&#xff01;把名片转成电子版保存到电脑上就完美啦&#xff01;但要是名片数量有点多&#xff0…...

JAVASE---方法的使用

方法概念及使用 什么是方法(method) 方法就是一个代码片段. 类似于 C 语言中的 "函数"。方法存在的意义(不要背, 重在体会): 1. 是能够模块化的组织代码(当代码规模比较复杂的时候)。 2. 做到代码被重复使用, 一份代码可以在多个位置使用。 3. 让代码更好理解更简单…...

CryptoJS.lib.WordArray.create、CryptoJS.enc.Base64介绍

1、CryptoJS.lib.WordArray.create&#xff1a;它是 CryptoJS 库中的一个方法&#xff0c;用于创建 WordArray 对象。WordArray 对象是 CryptoJS 库中用于处理二进制数据的基本数据类型。它通常用于表示加密算法的输入和输出。 2、CryptoJS.enc.Base64&#xff1a;它是 CryptoJ…...

linux 配置java环境变量

单个用户 vim ~/.bashrc 或者 vim ~/.bash_profile全局用户 vim /etc/profileexport JAVA_HOME/path/to/java export PATH$JAVA_HOME/bin:$PATH立即生效使用 source 命令 source ~/.bashrc source /etc/profilejava -version...

Mybatis异常Invalid bound statement (not found)原因之Mapper文件配置不匹配

模拟登录操作 $.post("/admin/login", {aname, pwd }, rt > {if (rt.code 200) {location.href "manager/index.html";return;}alert(rt.msg)});网页提示服务器代码错误 POST http://localhost:8888/admin/login 500后端显示无法找到Mapper中对应的…...

SAP中采购文档出现定价转换因子字段溢出是何原因?

近期处理了一笔用户反馈的主题问题。这个问题有意思的地方在于&#xff0c;多重错误的叠加&#xff0c;导致了问题在开始就暴露出来&#xff0c;可以将隐患消除在萌芽状态。 在公司的应用中&#xff0c;会由采购创建价格合同&#xff0c;物流参照价格合同创建计划协议。但采购…...

Linux6.33 Kubernetes kubectl详解

文章目录 计算机系统5G云计算第三章 LINUX Kubernetes kubectl详解一、陈述式资源管理方法1.基本信息查看2.项目的生命周期&#xff1a;创建-->发布-->更新-->回滚-->删除 二、声明式管理方法 计算机系统 5G云计算 第三章 LINUX Kubernetes kubectl详解 一、陈述…...

小程序uni-select溢出文字处理方式

<uni-data-select v-model="customFormData.limitedBy" :localdata="cancelWays" @change="change"></uni-data-select>溢出效果如下图...

【MacOS】mac OS 安装HP 打印机驱动 hp laserjet m1213nf mfp

先确认一下机器复印是否正常.确认一下打印机的硬件. 如果复印没问题 1. 下载v5.1集合包Hewlett-Packard 打印机驱动程序 v5.1.1 (OS X) (中国) 2. 苹果商城中,下载Pacifist&#xff0c;运行Pacifist&#xff0c;用Pacifist程序打开v5.1并安装 3. 电脑--系统偏好设置--打印…...

【搜索】DFS剪枝与优化

算法提高课笔记 目录 小猫爬山题意思路代码 数独题意思路代码 木棒题意思路代码 生日蛋糕题意思路代码 剪枝是什么意思呢&#xff1f; 我们知道&#xff0c;不管是内部搜索还是外部搜索&#xff0c;都可以形成一棵搜索树&#xff0c;如果将搜索树全部遍历一遍&#xff0c;效率…...

dfs之卒的遍历

题面 题目描述 在一张nm 的棋盘上&#xff08;如 6 行 7 列&#xff09;的最左上角(1,1) 的位置有一个卒。该卒只能向下或者向右走&#xff0c;且卒采取的策略是先向下&#xff0c;下边走到头就向右&#xff0c;请问从(1,1) 点走到 (n,m) 点可以怎样走&#xff0c;输出这些走法…...

Springboot整合activiti5,达梦数据库,mybatis中间件

Springboot整合activiti5&#xff0c;达梦数据库&#xff0c;mybatis中间件 问题现象解决方案 问题现象 由于工作流引擎不支持达梦数据库以及国产中间件&#xff0c;所以我们引入的时候会报错&#xff0c;这个时候就需要去改造代码和配置文件。各种文档和资料查找一天&#xf…...

使用Python + Flask搭建web服务

示例脚本 from flask import Flask# 获取一个实例对象 app Flask(__name__)# 1、注册 app.route(/reg, methods[get]) def reg():return {code: 200,msg: reg ok!}# 2、登录 app.route(/login, methods[get]) def login():return login ok&#xff01;if __name__ __main__:…...

Winform 打开文件夹、文件、拖拽上传

参考原文&#xff1a;https://blog.csdn.net/u012543266/article/details/21834073 1、打开文件 private void button1_Click(object sender, EventArgs e){OpenFileDialog dialog new OpenFileDialog();dialog.Multiselect true;//该值确定是否可以选择多个文件dialog.Titl…...

热评国内AI四小龙:此一时彼一时,彼此彼此

引言&#xff1a;阿里“清仓”全部持股 商汤科技表示“没啥事” 【科技明说 &#xff5c; 热点关注】 作为国内AI领域的知名科技上市公司&#xff0c;商汤科技SenseTime的一举一动都牵动着业内人士的心。 然而&#xff0c;商汤科技的财报表现没有出奇制胜&#xff0c;却让不…...

[国产MCU]-BL602开发实例-GPIO控制

GPIO与控制 文章目录 GPIO与控制1、GPIO介绍2、GPIO管理相关API介绍3、硬件准备4、软件准备5、代码实现3.1 GPIO输出3.2 GPIO输入3.3 GPIO中断BL602的GLB(Global Register)是芯片通用全局设定模块,主要包含了时钟管理、复位管理、总线管理、内存管理以及GPIO管理等功能。 本文…...

Firefox 配置 Burp_proxy 和 证书

安装代理拓展 安装拓展&#xff1a; chrome &#xff1a; switchomega firefox &#xff1a; foxyproxy 创建代理 &#xff1a; 127.0.0.1:8080 安装burp证书 先开启burp&#xff0c;然后切换到 burp 的代理访问 https://burp/ 下载证书打开firefox设置 - 搜索”证书“ -…...

基于Java+SpringBoot+Vue前后端分离仓库管理系统详细设计和实现

博主介绍&#xff1a;✌全网粉丝30W,csdn特邀作者、博客专家、CSDN新星计划导师、Java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专…...

PyTorch Lightning教程七:可视化

本节指导如何利用Lightning进行可视化和监控模型 为何需要跟踪参数 在模型开发中&#xff0c;我们跟踪感兴趣的值&#xff0c;例如validation_loss&#xff0c;以可视化模型的学习过程。模型开发就像驾驶一辆没有窗户的汽车&#xff0c;图表和日志提供了窗口&#xff0c;让我们…...

后端开发2.mongdb的集成

使用docker安装 安装 拉取镜像 docker pull mongo:4.4.14-focal 创建容器 docker run -itd --name mongo -p 8036:27017 mongo:4.4.14-focal --auth 配置管理员 进入容器 docker exec -it mongo bash 进入终端 mongo 进入admin数据库 use admin 创建管理员账户 db.c…...

Unity面板究极优化

首先对于大项目来说UI首选一定的UGUI&#xff0c;目前没有啥可选的余地。多一点都是对性能的负担&#xff0c;UGUI底层基于多线程技术&#xff0c;可以有效分担压力&#xff0c;对于一些不是那么重的面板几乎无感。 无论其他面板只是在此基础上修改的&#xff0c;但每多一层&am…...

C# App.config和Web.config加密

步骤1&#xff1a;创建加密命令 使用ASP.NET提供的命令工具aspnet_regiis来创建加密命令。 1、打开控制台窗口&#xff0c;在命令行中输入以下命令&#xff1a; cd C:\Windows\Microsoft.NET\Framework\v4.xxxxx aspnet_regiis.exe -pef connectionStrings "C:\MyAppFo…...

力扣:50. Pow(x, n)(Python3)

题目&#xff1a; 实现 pow(x, n) &#xff0c;即计算 x 的整数 n 次幂函数&#xff08;即&#xff0c;xn &#xff09;。 来源&#xff1a;力扣&#xff08;LeetCode&#xff09; 链接&#xff1a;力扣 示例&#xff1a; 示例 1&#xff1a; 输入&#xff1a;x 2.00000, n 1…...

scikit-plot 使用笔记

scikit-plot是基于sklearn和Matplotlib的库&#xff0c;主要的功能是对训练好的模型进行可视化。 安装&#xff1a; pip install scikit-plot 功能1&#xff1a;评估指标可视化 scikitplot.metrics.plot_confusion_matrix快速展示模型预测结果和标签计算得到的混淆矩阵。 im…...

2024考研408-计算机网络 第五章-传输层学习笔记

文章目录 前言一、传输层提供的服务1.1、传输层的功能1.2、传输层的两个协议&#xff08;TCP、UDP&#xff09;1.3、传输层的寻址与端口&#xff08;常见端口介绍&#xff09; 二、UDP协议2.1、认识UDP功能和特点2.2、UDP首部格式2.3、UDP伪首部字段分析2.4、伪首部校验UDP用户…...

【JS】一道解构面试题

文章目录 [TOC] 一道解构面试题题目运行结果 原理概念数组迭代器 答案答案(1)、在对象中添加一个数组迭代器1.使用临时数组添加迭代器2. 对象值输出结果3.使用Object.values(this);拿到对象的值 答案(2)、在对象原型上添加数组迭代器1.按步骤实现数组迭代器2. 简化步骤 答案(3)…...

24v转3.3v输出3A用什么芯片

问&#xff1a;客户需要一个能够将24V输入电压转换为3.3V输出电压&#xff0c;并且能够提供1-3A的电流输出的芯片。还希望它能够内置MOS管。有什么推荐的型号吗&#xff1f;&#xff08;vin24v、5v&#xff0c;vout3.3v&#xff0c;Io1-3A&#xff09; 答&#xff1a;推荐使用…...