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

做网站后付款/青海seo技术培训

做网站后付款,青海seo技术培训,手机新手学做网站,保定网站建设公司我是 ABin-阿斌:写一生代码,创一世佳话,筑一览芳华。 如果小伙伴们觉得文章有点 feel ,那就点个赞再走哦。 原文链接:https://sourl.cn/dRpJ6b 一、前言 在日常开发当中我们会使用很多的判空工具进行校验&#xff0…

我是 ABin-阿斌:写一生代码,创一世佳话,筑一览芳华。 如果小伙伴们觉得文章有点 feel ,那就点个赞再走哦。
在这里插入图片描述

原文链接:https://sourl.cn/dRpJ6b

一、前言

  • 在日常开发当中我们会使用很多的判空工具进行校验,今天我们就看看对字符串判空有哪些骚操作
  • StringUtils 是我们比较常用的工具类了,也许你两个都不知道,也许你除了isEmpty/isNotEmpty/isNotBlank/isBlank外并不知道还有isAnyEmpty/isNoneEmpty/isAnyBlank/isNoneBlank的存在。 那么,接下来让我们一起来探索org.apache.commons.lang3.StringUtils;这个工具类。

二、正文

1、isEmpty 系列

1.1、StringUtils.isEmpty()

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

1.2、StringUtils.isNotEmpty()

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

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

1.3、StringUtils.isAnyEmpty()

  • 是否有一个为空,只有一个为空,就为 true。
StringUtils.isAnyEmpty(null) = trueStringUtils.isAnyEmpty(null, "foo") = trueStringUtils.isAnyEmpty("", "bar") = trueStringUtils.isAnyEmpty("bob", "") = trueStringUtils.isAnyEmpty(" bob ", null) = trueStringUtils.isAnyEmpty(" ", "bar") = falseStringUtils.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;
}

1.4、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) {

2、isBank 系列

2.1、StringUtils.isBlank()

  • 是否为真空值(空格或者空值)
StringUtils.isBlank(null) = trueStringUtils.isBlank("") = trueStringUtils.isBlank(" ") = trueStringUtils.isBlank("bob") = falseStringUtils.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;
}

2.2、StringUtils.isNotBlank()

  • 是否真的不为空,不是空格或者空值 ,相当于!isBlank();
public static boolean isNotBlank(final CharSequence cs) {return !isBlank(cs);}

2.3、StringUtils.isAnyBlank()

  • 是否包含任何真空值(包含空格或空值)
StringUtils.isAnyBlank(null) = trueStringUtils.isAnyBlank(null, "foo") = trueStringUtils.isAnyBlank(null, null) = trueStringUtils.isAnyBlank("", "bar") = trueStringUtils.isAnyBlank("bob", "") = trueStringUtils.isAnyBlank(" bob ", null) = trueStringUtils.isAnyBlank(" ", "bar") = trueStringUtils.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;
}

2.4、StringUtils.isNoneBlank()

  • 是否全部都不包含空值或空格
StringUtils.isNoneBlank(null) = falseStringUtils.isNoneBlank(null, "foo") = falseStringUtils.isNoneBlank(null, null) = falseStringUtils.isNoneBlank("", "bar") = falseStringUtils.isNoneBlank("bob", "") = falseStringUtils.isNoneBlank(" bob ", null) = falseStringUtils.isNoneBlank(" ", "bar") = falseStringUtils.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);
}

3、StringUtils 的其他方法

  • 可以参考官方的文档,里面有详细的描述,有些方法还是很好用的。 StringUtils官方文档
方法名英文解释中文解释
IsEmpty/IsBlankchecks if a String contains text检查字符串是否包含文本
Trim/Stripremoves leading and trailing whitespace删除前导和尾随空格
Equals/Comparecompares two strings null-safe比较两个字符串是否为 null 安全的
startsWithcheck if a String starts with a prefix null-safe检查字符串是否以前缀 null 安全开头
endsWithcheck if a String ends with a suffix null-safe检查字符串是否以后缀 null 安全结尾
IndexOf/LastIndexOf/Containsnull-safe index-of checks包含空安全索引检查
IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyButindex-of any of a set of Strings任意一组字符串的索引
ContainsOnly/ContainsNone/ContainsAnydoes String contains only/none/any of these characters字符串是否仅包含/无/这些字符中的任何一个
Substring/Left/Right/Midnull-safe substring extractions字符串安全提取
SubstringBefore/SubstringAfter/SubstringBetweensubstring extraction relative to other strings相对其他字符串的字符串提取
Split/Joinsplits a String into an array of substrings and vice versa将字符串拆分为子字符串数组,反之亦然
Remove/Deleteremoves part of a String删除字符串的一部分
Replace/OverlaySearches a String and replaces one String with another搜索字符串,然后用另一个字符串替换
Chomp/Chopremoves the last part of a String删除字符串的最后一部分
AppendIfMissingappends a suffix to the end of the String if not present如果不存在后缀,则在字符串的末尾附加一个后缀
PrependIfMissingprepends a prefix to the start of the String if not present如果不存在前缀,则在字符串的开头添加前缀
LeftPad/RightPad/Center/Repeatpads a String填充字符串
UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalizechanges the case of a String更改字符串的大小写
CountMatchescounts the number of occurrences of one String in another计算一个字符串在另一个字符串中出现的次数
IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintablechecks the characters in a String检查字符串中的字符
DefaultStringprotects against a null input String防止输入字符串为空
Rotaterotate (circular shift) a String旋转(循环移位)字符串
Reverse/ReverseDelimitedreverses a String反转字符串
Abbreviateabbreviates a string using ellipsis or another given String使用省略号或另一个给定的 String 缩写一个字符串
Differencecompares Strings and reports on their differences比较字符串并报告其差异
LevenshteinDistancethe number of changes needed to change one String into another将一个 String 转换为另一个 String 所需的更改次数
http://www.jmfq.cn/news/4988305.html

相关文章:

  • 网站内链符号/企业网站源码
  • DW做网站入门步骤教学/聊石家庄seo
  • 安平县做网站的有哪些/北京建站公司
  • 制作论坛做网站/网址大全百度
  • 青岛模板做网站/天津网站策划
  • 怎么做网站可手机看/全国人大常委会
  • 美丽寮步网站建设价钱/创建网站步骤
  • 公众号建网站/好用的seo软件
  • 上海营销型网站建设公司/seo网络推广机构
  • 做网站需要前置审批/网站seo 优化
  • 淘宝现在不能发布网站建设/公司业务推广
  • 17网站一起做网店怎么下单/百度关键词搜索怎么弄
  • 重庆工厂网站建设/成都网络推广运营公司
  • 网站开发报价说明/站长工具友链检测
  • 网站正在建设中 公告/百度推广seo优化
  • 龙溪网站建设哪家便宜/营销广告文案
  • 官方网站建设 招标公告/成都网站维护
  • 洛阳网站建设行业/游戏推广代理平台
  • 网站搭建说明/西安网约车平台
  • 室内装修3d动态演示效果图/seo网站推广助理
  • 专业的网站建设企业/seo查询排名系统
  • 自己做民宿在什么网站上投放/游戏代理加盟平台
  • 源码网站下载/关键词优化价格表
  • dw做网站怎么排版/百度应用市场下载安装
  • 企业网站怎么做的更好/网页模板图片
  • 想自己做淘宝有什么网站吗/seo怎样优化网站
  • 网站策划案例/seo网站推广有哪些
  • 企业网站的建立不能缺少哪些细节/爱站网权重查询
  • 凡客诚品的商业模式/搜索引擎优化入门
  • 苏州做公司网站/找相似图片 识别