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类定义与字符串处理某些词。




StringUtilsnull静静地处理输入字符串。这就是说,一个null输入将返回null。在哪里booleanint正在退货的细节因方法而异。


处理的一个副作用null是a NullPointerException应该被认为是一个错误 StringUtils(除了被弃用的方法)。


这个类中的方法给出了示例代码来解释它们的操作。该符号*用于指示包括的任何输入null

 
检查字符串是否为空

    isNotEmpty 将空格也作为参数,isNotBlank 则排除空格参数


isNoneEmpty 可添加多个参数将空格也作为参数 , isNoneBlank 可添加多个参数,排除空格参数

去掉字符串前后的空白
Trim/Strip 比较两个字符串是否相等
Equals  检查字符串是否以null前缀为开头
startsWith  检查字符串是否以null后缀为结尾 检查字符串是否包含一个特定的字符
IndexOf / LastIndexOf / Contains


最新文章

  1. Android数据存储之SharedPreferences及如何安全存储
  2. ASP.NET网站优化(转自一位博友的文章,写的非常好)
  3. ASP.NET 页生命周期
  4. iOS UITableView 分割线从零开始
  5. 使用phpmyadmin修改XAMPP中MySQL的默认空密码
  6. JVM参数(二)参数分类和即时(JIT)编译器诊断
  7. IOS—静态方法(类方法)和实例方法
  8. 《你不知道的JavaScript》读书笔记(二)词法作用域
  9. 配置Pycharm3.4.1调试edX Devstack
  10. Linux下rsync增加SSH端口号的用法
  11. centerOS安装chkrootkit
  12. tab切换插件开发
  13. 前端之BOM
  14. Metasploit运行环境内存不要低于2GB
  15. lateinit 的使用限制
  16. blfs(systemd版本)学习笔记-安装lrzsz软件包实现ssh远程传输文件到lfs系统
  17. xshell 5连接NAT模式的虚拟机
  18. delete/truncate/drop table的区别以及锁在这里的角色
  19. 【Android】详解Android动画
  20. STM8串口初始化寄存器配置

热门文章

  1. [Linux-CentOS7]yum清华源CentOS7
  2. python制作ico图标
  3. 11种常用css样式之开篇文本字体学习
  4. cookie的设置与取值
  5. linux下(centos7)docker安装
  6. 「BZOJ3065」带插入区间K小值 [分块]
  7. 安装MongoDB到CentOS(YUM)
  8. Wannafly Winter Camp 2020 Day 7E 上升下降子序列 - 数学
  9. kafka消费服务调优
  10. Centos 7 firewall的防火墙的规则