JAVA StringUtils工具类




org.apache.commons.lang 
Class StringUtils

java.lang.Object
  
extended by 
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




原文地址:https://www.cnblogs.com/yccmelody/p/8117318.html