public class StrUtil extends CharSequenceUtil
Modifier and Type | Field and Description |
---|---|
static String |
AT
字符串常量:艾特
"@" |
static String |
BACKSLASH
字符串常量:反斜杠
"\\" |
static String |
BRACKET_END
字符串常量:中括号(右)
"]" |
static String |
BRACKET_START
字符串常量:中括号(左)
"[" |
static char |
C_AT
字符常量:艾特
'@' |
static char |
C_BACKSLASH
字符常量:反斜杠
'\\' |
static char |
C_BRACKET_END
字符常量:中括号(右)
']' |
static char |
C_BRACKET_START
字符常量:中括号(左)
'[' |
static char |
C_COLON
字符常量:冒号
':' |
static char |
C_COMMA
字符常量:逗号
',' |
static char |
C_CR
字符常量:回车符
'\r' |
static char |
C_DELIM_END
字符常量:花括号(右)
'}' |
static char |
C_DELIM_START
字符常量:花括号(左)
'{' |
static char |
C_DOT
字符常量:点
'.' |
static char |
C_LF
字符常量:换行符
'\n' |
static char |
C_SLASH
字符常量:斜杠
'/' |
static char |
C_SPACE
字符常量:空格符
' ' |
static char |
C_TAB
字符常量:制表符
'\t' |
static char |
C_UNDERLINE
字符常量:下划线
'_' |
static String |
COLON
字符串常量:冒号
":" |
static String |
COMMA
字符串常量:逗号
"," |
static String |
CR
字符串常量:回车符
"\r" 解释:该字符常用于表示 Linux 系统和 MacOS 系统下的文本换行 |
static String |
CRLF
字符串常量:Windows 换行
"\r\n" 解释:该字符串常用于表示 Windows 系统下的文本换行 |
static String |
DASHED
字符串常量:减号(连接符)
"-" |
static String |
DELIM_END
字符串常量:花括号(右)
"}" |
static String |
DELIM_START
字符串常量:花括号(左)
"{" |
static String |
DOT
字符串常量:点
"." |
static String |
DOUBLE_DOT
字符串常量:双点
".." 用途:作为指向上级文件夹的路径,如: "../path" |
static String |
EMPTY_JSON
字符串常量:空 JSON
"{}" |
static String |
HTML_AMP
字符串常量:HTML And 符转义
"&" -> "&" |
static String |
HTML_APOS
字符串常量:HTML 单引号转义
"&apos" -> "'" |
static String |
HTML_GT
字符串常量:HTML 大于号转义
">" -> ">" |
static String |
HTML_LT
字符串常量:HTML 小于号转义
"<" -> "<" |
static String |
HTML_NBSP
字符串常量:HTML 空格转义
" " -> " " |
static String |
HTML_QUOTE
字符串常量:HTML 双引号转义
""" -> "\"" |
static String |
LF
字符串常量:换行符
"\n" |
static String |
SLASH
字符串常量:斜杠
"/" |
static String |
TAB
字符串常量:制表符
"\t" |
static String |
UNDERLINE
字符串常量:下划线
"_" |
EMPTY, INDEX_NOT_FOUND, NULL, SPACE
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 String |
format(CharSequence template,
Map<?,?> map)
格式化文本,使用 {varName} 占位
map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ---=》 aValue and bValue |
static String |
format(CharSequence template,
Map<?,?> map,
boolean ignoreNull)
格式化文本,使用 {varName} 占位
map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) ---=》 aValue and bValue |
static StringReader |
getReader(CharSequence str)
获得StringReader
|
static StringWriter |
getWriter()
获得StringWriter
|
static boolean |
isBlankIfStr(Object obj)
如果对象是字符串是否为空白,空白的定义如下:
|
static boolean |
isEmptyIfStr(Object obj)
如果对象是字符串是否为空串,空的定义如下:
|
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(byte[] bytes,
String charset)
将byte数组转为字符串
|
static String |
str(Byte[] bytes,
String charset)
将Byte数组转为字符串
|
static String |
str(ByteBuffer data,
Charset charset)
将编码的byteBuffer数据转换为字符串
|
static String |
str(ByteBuffer data,
String charset)
将编码的byteBuffer数据转换为字符串
|
static String |
str(Object obj,
Charset charset)
将对象转为字符串
|
static String |
str(Object obj,
String charsetName)
将对象转为字符串
|
static StrBuilder |
strBuilder()
创建StrBuilder对象
|
static StrBuilder |
strBuilder(int capacity)
创建StrBuilder对象
|
static String |
toString(Object obj)
调用对象的toString方法,null会返回“null”
|
static void |
trim(String[] strs)
给定字符串数组全部做去首尾空格
|
static String |
utf8Str(Object obj)
将对象转为字符串
|
static String |
uuid()
生成随机UUID
|
addPrefixIfNot, addSuffixIfNot, appendIfMissing, appendIfMissing, appendIfMissingIgnoreCase, blankToDefault, brief, builder, byteBuffer, byteLength, bytes, bytes, bytes, center, center, center, cleanBlank, compare, compareIgnoreCase, compareVersion, concat, contains, contains, containsAny, containsAny, containsAnyIgnoreCase, containsBlank, containsIgnoreCase, containsOnly, count, count, cut, emptyIfNull, emptyToDefault, emptyToNull, endWith, endWith, endWith, endWithAny, endWithAnyIgnoreCase, endWithIgnoreCase, equals, equals, equalsAny, equalsAny, equalsAnyIgnoreCase, equalsCharAt, equalsIgnoreCase, filter, firstNonBlank, firstNonEmpty, firstNonNull, format, genGetter, genSetter, getContainsStr, getContainsStrIgnoreCase, getGeneralField, hasBlank, hasEmpty, hide, indexedFormat, indexOf, indexOf, indexOf, indexOf, indexOfIgnoreCase, indexOfIgnoreCase, isAllBlank, isAllCharMatch, isAllEmpty, isAllNotBlank, isAllNotEmpty, isBlank, isBlankOrUndefined, isEmpty, isEmptyOrUndefined, isLowerCase, isNotBlank, isNotEmpty, isNullOrUndefined, isSubEquals, isSurround, isSurround, isUpperCase, isWrap, isWrap, isWrap, isWrap, join, lastIndexOf, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, length, lowerFirst, maxLength, move, nullToDefault, nullToEmpty, ordinalIndexOf, padAfter, padAfter, padPre, padPre, prependIfMissing, prependIfMissing, prependIfMissingIgnoreCase, removeAll, removeAll, removeAllLineBreaks, removeAny, removePreAndLowerFirst, removePreAndLowerFirst, removePrefix, removePrefixIgnoreCase, removeSufAndLowerFirst, removeSuffix, removeSuffixIgnoreCase, repeat, repeat, repeatAndJoin, repeatByLength, replace, replace, replace, replace, replace, replace, replaceChars, replaceChars, replaceIgnoreCase, split, split, split, split, split, split, split, splitToArray, splitToArray, splitToInt, splitToInt, splitToLong, splitToLong, splitTrim, splitTrim, splitTrim, splitTrim, startWith, startWith, startWith, startWith, startWithAny, startWithIgnoreCase, startWithIgnoreEquals, str, strBuilder, strip, strip, stripIgnoreCase, stripIgnoreCase, sub, subAfter, subAfter, subBefore, subBefore, subBetween, subBetween, subBetweenAll, subBetweenAll, subByCodePoint, subPre, subPreGbk, subSuf, subSufByLength, subWithLength, swapCase, toCamelCase, toSymbolCase, totalLength, toUnderlineCase, trim, trim, trimEnd, trimStart, trimToEmpty, trimToNull, unWrap, unWrap, unWrap, upperFirst, upperFirstAndAddPre, utf8Bytes, wrap, wrap, wrapAll, wrapAllIfMissing, wrapAllWithPair, wrapAllWithPairIfMissing, wrapIfMissing
public static final char C_SPACE
' '
public static final char C_TAB
'\t'
public static final char C_DOT
'.'
public static final char C_SLASH
'/'
public static final char C_BACKSLASH
'\\'
public static final char C_CR
'\r'
public static final char C_LF
'\n'
public static final char C_UNDERLINE
'_'
public static final char C_COMMA
','
public static final char C_DELIM_START
'{'
public static final char C_DELIM_END
'}'
public static final char C_BRACKET_START
'['
public static final char C_BRACKET_END
']'
public static final char C_COLON
':'
public static final char C_AT
'@'
public static final String TAB
"\t"
public static final String DOT
"."
public static final String DOUBLE_DOT
".."
"../path"
public static final String SLASH
"/"
public static final String BACKSLASH
"\\"
public static final String CR
"\r"
public static final String LF
"\n"
public static final String CRLF
"\r\n"
public static final String UNDERLINE
"_"
public static final String DASHED
"-"
public static final String COMMA
","
public static final String DELIM_START
"{"
public static final String DELIM_END
"}"
public static final String BRACKET_START
"["
public static final String BRACKET_END
"]"
public static final String COLON
":"
public static final String AT
"@"
public static final String HTML_NBSP
" " -> " "
public static final String HTML_AMP
"&" -> "&"
public static final String HTML_QUOTE
""" -> "\""
public static final String HTML_APOS
"&apos" -> "'"
public static final String HTML_LT
"<" -> "<"
public static final String HTML_GT
">" -> ">"
public static final String EMPTY_JSON
"{}"
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
- 对象CharSequenceUtil.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, String charsetName)
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
obj
- 对象charsetName
- 字符集public static String str(Object obj, Charset charset)
1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
obj
- 对象charset
- 字符集public static String str(byte[] bytes, String charset)
bytes
- byte数组charset
- 字符集public static String str(byte[] data, Charset charset)
data
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static String str(Byte[] bytes, String charset)
bytes
- byte数组charset
- 字符集public static String str(Byte[] data, Charset charset)
data
- 字符串charset
- 字符集,如果此字段为空,则解码的结果取决于平台public static String str(ByteBuffer data, String charset)
data
- 数据charset
- 字符集,如果为空使用当前系统字符集public static String str(ByteBuffer data, Charset charset)
data
- 数据charset
- 字符集,如果为空使用当前系统字符集public static String toString(Object obj)
obj
- 对象public static StringBuilder builder()
public static StrBuilder strBuilder()
public static StringBuilder builder(int capacity)
capacity
- 初始大小public static StrBuilder strBuilder(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
- 字符串2public static String similar(String str1, String str2, int scale)
str1
- 字符串1str2
- 字符串2scale
- 相似度public static String uuid()
IdUtil.randomUUID()
public static String format(CharSequence template, Map<?,?> map)
template
- 文本模板,被替换的部分用 {key} 表示map
- 参数值对public static String format(CharSequence template, Map<?,?> map, boolean ignoreNull)
template
- 文本模板,被替换的部分用 {key} 表示map
- 参数值对ignoreNull
- 是否忽略 null
值,忽略则 null
值对应的变量不被替换,否则替换为""Copyright © 2021. All rights reserved.