public class StrUtil extends CharSequenceUtil implements StrPool
INDEX_NOT_FOUND
EMPTY, NULL
AT, BACKSLASH, BRACKET_END, BRACKET_START, COLON, COMMA, CR, CRLF, DASHED, DELIM_END, DELIM_START, DOT, DOUBLE_DOT, EMPTY_JSON, LF, SLASH, SPACE, TAB, UNDERLINE
Constructor and Description |
---|
StrUtil() |
Modifier and Type | Method and Description |
---|---|
static StringBuilder |
builder()
创建StringBuilder对象
|
static StringBuilder |
builder(int capacity)
创建StringBuilder对象
|
static String |
fill(String str,
char filledChar,
int len,
boolean isPre)
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
|
static String |
fillAfter(String str,
char filledChar,
int len)
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
字符填充于字符串后 |
static String |
fillBefore(String str,
char filledChar,
int len)
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串
字符填充于字符串前 |
static StringReader |
getReader(CharSequence str)
获得StringReader
|
static StringWriter |
getWriter()
获得StringWriter
|
static boolean |
isBlankIfStr(Object obj)
如果对象是字符串是否为空白,空白的定义如下:
null
空字符串:""
空格、全角空格、制表符、换行符,等不可见字符
例:
StrUtil.isBlankIfStr(null) // true
StrUtil.isBlankIfStr("") // true
StrUtil.isBlankIfStr(" \t\n") // true
StrUtil.isBlankIfStr("abc") // false
注意:该方法与 isEmptyIfStr(Object) 的区别是:
该方法会校验空白字符,且性能相对于 isEmptyIfStr(Object) 略慢。 |
static boolean |
isEmptyIfStr(Object obj)
如果对象是字符串是否为空串,空的定义如下:
null
空字符串:""
例:
StrUtil.isEmptyIfStr(null) // true
StrUtil.isEmptyIfStr("") // true
StrUtil.isEmptyIfStr(" \t\n") // false
StrUtil.isEmptyIfStr("abc") // false
注意:该方法与 isBlankIfStr(Object) 的区别是:该方法不校验空白字符。 |
static String |
reverse(String str)
反转字符串
例如:abcd =》dcba |
static double |
similar(String str1,
String str2)
计算两个字符串的相似度
|
static String |
similar(String str1,
String str2,
int scale)
计算两个字符串的相似度百分比
|
static String |
str(byte[] data,
Charset charset)
解码字节码
|
static String |
str(Byte[] data,
Charset charset)
解码字节码
|
static String |
str(ByteBuffer data,
Charset charset)
将编码的byteBuffer数据转换为字符串
|
static String |
str(Object obj,
Charset charset)
将对象转为字符串
1、Byte数组和ByteBuffer会被转换为对应字符串的数组
2、char[]会直接构造String
3、对象数组会调用Arrays.toString方法
|
static String |
strFast(char[] value)
JDK8中,通过
String(char[] value, boolean share) 这个内部构造创建String对象。 |
static void |
trim(String[] strs)
给定字符串数组全部做去首尾空格
|
static String |
utf8Str(Object obj)
将对象转为字符串
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 |
addPrefixIfNot, addSuffixIfNot, appendIfMissing, appendIfMissing, appendIfMissingIgnoreCase, brief, builder, builder, byteLength, center, center, center, cleanBlank, codeLength, commonPrefix, commonSuffix, compare, compareIgnoreCase, compareVersion, concat, contains, contains, containsAll, containsAny, containsAny, containsAnyIgnoreCase, containsBlank, containsIgnoreCase, containsOnly, count, count, cut, defaultIfBlank, defaultIfBlank, defaultIfBlank, defaultIfEmpty, defaultIfEmpty, defaultIfEmpty, defaultIfNull, defaultIfNull, defaultIfNull, emptyIfNull, endWith, endWith, endWith, endWith, endWithAny, endWithAnyIgnoreCase, endWithIgnoreCase, equals, equals, equalsAny, equalsAny, equalsAnyIgnoreCase, equalsCharAt, equalsIgnoreCase, filter, firstNonBlank, firstNonEmpty, firstNonNull, fixLength, forEach, forEach, format, formatByBean, formatByMap, formatByMap, getContainsStr, getContainsStrIgnoreCase, hide, indexedFormat, indexOf, indexOf, indexOf, indexOf, indexOf, indexOfIgnoreCase, indexOfIgnoreCase, isCharEquals, isLowerCase, isNumeric, isSubEquals, isSubEquals, isUpperCase, isWrap, isWrap, isWrap, isWrap, join, join, lastIndexOf, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, length, limitByteLength, limitByteLengthUtf8, limitLength, lowerAt, lowerFirst, move, normalize, nullIfBlank, nullIfEmpty, ordinalIndexOf, padAfter, padAfter, padPre, padPre, prependIfMissing, prependIfMissing, prependIfMissingIgnoreCase, removeAll, removeAll, removeAll, removeAllLineBreaks, removeAllPrefix, removeAllSuffix, removePreAndLowerFirst, removePreAndLowerFirst, removePrefix, removePrefix, removePrefixIgnoreCase, removeSufAndLowerFirst, removeSuffix, removeSuffixIgnoreCase, repeat, repeat, repeatAndJoin, repeatByLength, replace, replace, replace, replace, replace, replaceAt, replaceByCodePoint, replaceByCodePoint, replaceChars, replaceChars, replaceFirst, replaceIgnoreCase, replaceLast, startWith, startWith, startWith, startWith, startWithAny, startWithAnyIgnoreCase, startWithIgnoreCase, startWithIgnoreEquals, strip, strip, strip, stripAll, stripAll, stripAll, stripIgnoreCase, stripIgnoreCase, sub, subAfter, subAfter, subBefore, subBefore, subBetween, subBetween, subBetweenAll, subBetweenAll, subByCodePoint, subByLength, subPre, subPreGbk, subPreGbk, subSuf, subSufByLength, swapCase, toCamelCase, toCamelCase, toChars, toString, toStringOrEmpty, toStringOrNull, toSymbolCase, totalLength, toUnderlineCase, trim, trim, trim, trimPrefix, trimSuffix, trimToEmpty, trimToNull, unWrap, unWrap, unWrap, upperAt, upperFirst, upperFirstAndAddPre, wrap, wrap, wrap, wrapAll, wrapAllIfMissing, wrapAllWithPair, wrapAllWithPairIfMissing, wrapIfMissing
hasBlank, hasEmpty, hasEmpty, isAllBlank, isAllCharMatch, isAllEmpty, isAllEmpty, isAllNotBlank, isAllNotEmpty, isBlank, isBlankOrUndefined, isEmpty, isEmptyOrUndefined, isNotBlank, isNotEmpty, isNullOrUndefined
public static boolean isBlankIfStr(Object obj)
如果对象是字符串是否为空白,空白的定义如下:
null
""
例:
StrUtil.isBlankIfStr(null) // true
StrUtil.isBlankIfStr("") // true
StrUtil.isBlankIfStr(" \t\n") // true
StrUtil.isBlankIfStr("abc") // false
注意:该方法与 isEmptyIfStr(Object)
的区别是:
该方法会校验空白字符,且性能相对于 isEmptyIfStr(Object)
略慢。
obj
- 对象StrValidator.isBlank(CharSequence)
public static boolean isEmptyIfStr(Object obj)
如果对象是字符串是否为空串,空的定义如下:
null
""
例:
StrUtil.isEmptyIfStr(null) // true
StrUtil.isEmptyIfStr("") // true
StrUtil.isEmptyIfStr(" \t\n") // false
StrUtil.isEmptyIfStr("abc") // false
注意:该方法与 isBlankIfStr(Object)
的区别是:该方法不校验空白字符。
obj
- 对象public static void trim(String[] strs)
strs
- 字符串数组public static String utf8Str(Object obj)
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
obj
- 对象public static String str(Object obj, Charset charset)
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、char[]会直接构造String 3、对象数组会调用Arrays.toString方法
obj
- 对象charset
- 字符集public static String str(byte[] data, Charset charset)
data
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static String str(Byte[] data, Charset charset)
data
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static String str(ByteBuffer data, Charset charset)
data
- 数据charset
- 字符集,如果为空使用当前系统字符集public static String strFast(char[] value)
String(char[] value, boolean share)
这个内部构造创建String对象。value
- char[]值,注意这个数组不可修改!!public static StringBuilder builder()
public static StringBuilder builder(int capacity)
capacity
- 初始大小public static StringReader getReader(CharSequence str)
str
- 字符串public static StringWriter getWriter()
public static String reverse(String str)
str
- 被反转的字符串public static String fillBefore(String str, char filledChar, int len)
str
- 被填充的字符串filledChar
- 填充的字符len
- 填充长度public static String fillAfter(String str, char filledChar, int len)
str
- 被填充的字符串filledChar
- 填充的字符len
- 填充长度public static String fill(String str, char filledChar, int len, boolean isPre)
str
- 被填充的字符串filledChar
- 填充的字符len
- 填充长度isPre
- 是否填充在前public static double similar(String str1, String str2)
str1
- 字符串1str2
- 字符串2Copyright © 2025. All rights reserved.