JAVA StringUtils工具类
org.apache.commons.lang
Class StringUtils
java.lang.Object
org.apache.commons.lang.StringUtils
public class StringUtilsextends Object
Operations on String that are null safe.
- IsEmpty/IsBlank - checks if a String contains text
- Trim/Strip - removes leading and trailing whitespace
- Equals - compares two strings null-safe
- startsWith - check if a String starts with a prefix null-safe
- endsWith - check if a String ends with a suffix null-safe
- IndexOf/LastIndexOf/Contains - null-safe index-of checks
- IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
- ContainsOnly/ContainsNone/ContainsAny - does String contains only/none/any of these characters
- Substring/Left/Right/Mid - null-safe substring extractions
- SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
- Split/Join - splits a String into an array of substrings and vice versa
- Remove/Delete - removes part of a String
- Replace/Overlay - Searches a String and replaces one String with another
- Chomp/Chop - removes the last part of a String
- LeftPad/RightPad/Center/Repeat - pads a String
- UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
- CountMatches - counts the number of occurrences of one String in another
- IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
- DefaultString - protects against a null input String
- Reverse/ReverseDelimited - reverses a String
- Abbreviate - abbreviates a string using ellipsis
- Difference - compares Strings and reports on their differences
- LevensteinDistance - the number of changes needed to change one String into another
The StringUtils class defines certain words related to String handling.
- null -
null - empty - a zero-length string (
"") - space - the space character (
' ', char 32) - whitespace - the characters defined by
Character.isWhitespace(char) - trim - the characters <= 32 as in
String.trim()
StringUtils handles null input Strings quietly. That is to say that a null input will return null. Where a boolean or int is being returned details vary by method.
A side effect of the null handling is that a NullPointerException should be considered a bug in StringUtils (except for deprecated methods).
Methods in this class give sample code to explain their operation. The symbol * is used to indicate any input including null.
翻译:Google
org.apache.commons.lang
类StringUtils
java.lang.Object
org.apache.commons.lang.StringUtils
公共类StringUtils扩展Object
这样做的操作String是 null安全的。
- IsEmpty / IsBlank - 检查一个String是否包含文本
- 修剪/去除 - 去除前导和尾随的空白
- 等于 - 比较两个字符串无效
- startsWith - 检查一个字符串是否以一个前缀为null开头
- endsWith - 检查一个String是否以一个后缀为null结尾
- IndexOf / LastIndexOf / Contains - 无效索引的检查
- IndexOfAny / LastIndexOfAny / IndexOfAnyBut / LastIndexOfAnyBut - 索引 - 任何一组字符串
- ContainsOnly / ContainsNone / ContainsAny - 是String只包含/ none /任何这些字符
- 子字符串/左/右/中 - 零安全子串提取
- SubstringBefore / SubstringAfter / SubstringBetween - 相对于其他字符串的子字符串提取
- 拆分/连接 - 将一个字符串拆分为一个子字符串数组,反之亦然
- 删除/删除 - 删除部分字符串
- 替换/覆盖 - 搜索一个字符串并用另一个替换一个字符串
- Chomp / Chop - 删除字符串的最后部分
- 左键盘/右键盘/中心/重复 - 填充字符串
- UpperCase / LowerCase / SwapCase / Capitalize / Uncapitalize - 更改字符串的大小写
- CountMatches - 统计另一个字符串的出现次数
- IsAlpha / IsNumeric / IsWhitespace / IsAsciiPrintable - 检查字符串中的字符
- DefaultString - 防止空输入字符串
- Reverse / ReverseDelimited - 反转字符串
- 缩写 - 使用省略号缩写字符串
- 差异 - 比较字符串和报告差异
- LevensteinDistance - 将一个字符串更改为另一个字符串所需的更改次数
在StringUtils类定义与字符串处理某些词。
- 空值 -
null - 空 - 一个零长度的字符串(
"") - 空格 - 空格字符(
' 'char 32) - 空格 - 由...定义的字符
Character.isWhitespace(char) - 修剪 - 在<= 32的字符
String.trim()
StringUtilsnull静静地处理输入字符串。这就是说,一个null输入将返回null。在哪里boolean或int正在退货的细节因方法而异。
处理的一个副作用null是a NullPointerException应该被认为是一个错误 StringUtils(除了被弃用的方法)。
这个类中的方法给出了示例代码来解释它们的操作。该符号*用于指示包括的任何输入null。
检查字符串是否为空
isNotEmpty 将空格也作为参数,isNotBlank 则排除空格参数
isNoneEmpty 可添加多个参数将空格也作为参数 , isNoneBlank 可添加多个参数,排除空格参数 去掉字符串前后的空白
Trim/Strip 比较两个字符串是否相等
Equals 检查字符串是否以null前缀为开头
startsWith 检查字符串是否以null后缀为结尾 检查字符串是否包含一个特定的字符
IndexOf / LastIndexOf / Contains
JAVA StringUtils工具类的更多相关文章
- StringUtils工具类常用方法汇总2(截取、去除空白、包含、查询索引)
在上一篇中总结了StringUtils工具类在判断字符串为空,大小写转换,移除字符或字符序列,替换,反转,切割合并等方面的方法,这次再汇总一下其它常用的方法. 一.截取 StringUtils ...
- java 常用工具类
1. org.apache.commons.collections4包提供CollectionUtils.MapUtils.ListUtils.SetUtils等工具类: 2. org.apache. ...
- 小记Java时间工具类
小记Java时间工具类 废话不多说,这里主要记录以下几个工具 两个时间只差(Data) 获取时间的格式 格式化时间 返回String 两个时间只差(String) 获取两个时间之间的日期.月份.年份 ...
- 基于StringUtils工具类的常用方法介绍(必看篇)
前言:工作中看到项目组里的大牛写代码大量的用到了StringUtils工具类来做字符串的操作,便学习整理了一下,方便查阅. isEmpty(String str) 是否为空,空格字符为false is ...
- Java开发工具类集合
Java开发工具类集合 01.MD5加密工具类 import java.security.MessageDigest; import java.security.NoSuchAlgorithmExce ...
- Java Properties工具类详解
1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...
- Java json工具类,jackson工具类,ObjectMapper工具类
Java json工具类,jackson工具类,ObjectMapper工具类 >>>>>>>>>>>>>>> ...
- Spring的StringUtils工具类
本文是转载文章,感觉比较好,如有侵权,请联系本人,我将及时删除. 原文网址:<Spring的StringUtils工具类> org.springframework.util.StringU ...
- Java日期工具类,Java时间工具类,Java时间格式化
Java日期工具类,Java时间工具类,Java时间格式化 >>>>>>>>>>>>>>>>>&g ...
随机推荐
- css实现文字过长显示省略号的方法
<div class="title">当对象内文本溢出时显示省略标记</div> 这是一个例子,其实我们只需要显示如下长度: css实现网页中文字过长截取. ...
- JAVA架构之单点登录 任务调度 权限管理 性能优化大型项目实战
单点登录SSO(Single Sign On)说得简单点就是在一个多系统共存的环境下,用户在一处登录后,就不用在其他系统中登录,也就是用户的一次登录能得到其他所有系统的信任.单点登录在大型网站里使用得 ...
- 深入源码分析SpringMVC执行过程
本文主要讲解 SpringMVC 执行过程,并针对相关源码进行解析. 首先,让我们从 Spring MVC 的四大组件:前端控制器(DispatcherServlet).处理器映射器(HandlerM ...
- StarUML之二、StarUML初识
为什么用StarUML UML建模工具比较常见的PowerDesigner ROSE StarUML starUML-开源免费(1-2百M),PowerDesigner-精细和一体化(6-7百M),R ...
- [红日安全]Web安全Day2 - XSS跨站实战攻防
本文由红日安全成员: Aixic 编写,如有不当,还望斧正. 大家好,我们是红日安全-Web安全攻防小组.此项目是关于Web安全的系列文章分享,还包含一个HTB靶场供大家练习,我们给这个项目起了一个名 ...
- 记一次Postgres CPU爆满故障
问题描述 公司项目测试环境调用某些接口的时候,服务器立即崩溃,并一定时间内无法提供服务. 问题排查 服务器配置不够 第一反应是服务器需要升配啦,花钱解决一切!毕竟测试服务器配置确实不高,2CPU + ...
- Linux学习Day6:编写Shell脚本
Shell脚本命令的工作方式有两种: 交互式(Interactive):用户每输入一条命令就立即执行. 批处理(Batch):由用户事先编写好一个完整的Shell脚本,Shell会一次性执行脚本中诸多 ...
- 【STM32H7教程】第47章 STM32H7的FMC总线基础知识和HAL库API
完整教程下载地址:http://www.armbbs.cn/forum.php?mod=viewthread&tid=86980 第47章 STM32H7的FMC总线基础知识和HA ...
- vue更改数组中的值
根据下标更改时 vm为新建的vue对象 ind为数组 第一个e为在数组ind中e索引位置 第二个e为更改为值e vm.$set(vm.ind,e,e) 常规更改 arr为数组 //添加 arr.pus ...
- Kafka消费者没有收到通知的分析
今天遇到两位三方人员跟我反馈,某微服务的异步接口功能不正常了,由于该异步接口采用Kafka异步消息的方案,对方说没有收到Kafka给消费者的通知,根据此问题,联系了相关人员进行了分析: (一)明确环境 ...
