类 StrJoiner
- java.lang.Object
-
- cc.shacocloud.mirage.utils.charSequence.StrJoiner
-
- 所有已实现的接口:
Serializable,Appendable
public class StrJoiner extends Object implements Appendable, Serializable
字符串连接器(拼接器),通过给定的字符串和多个元素,拼接为一个字符串
相较于StringJoiner提供更加灵活的配置,包括:- 支持任意Appendable接口实现
- 支持每个元素单独wrap
- 支持自定义null的处理逻辑
- 支持自定义默认结果
- 另请参阅:
- 序列化表格
-
-
嵌套类概要
嵌套类 修饰符和类型 类 说明 static classStrJoiner.NullModenull处理的模式
-
构造器概要
构造器 构造器 说明 StrJoiner(Appendable appendable, CharSequence delimiter)构造StrJoiner(Appendable appendable, CharSequence delimiter, CharSequence prefix, CharSequence suffix)构造StrJoiner(CharSequence delimiter)构造StrJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)构造
-
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 StrJoinerappend(char c)<E> StrJoinerappend(@NotNull Iterable<E> iterable, java.util.function.Function<? super E,? extends CharSequence> toStrFunc)追加Iterator中的元素到拼接器中StrJoinerappend(CharSequence csq)StrJoinerappend(CharSequence csq, int startInclude, int endExclude)StrJoinerappend(Object obj)追加对象到拼接器中<E> StrJoinerappend(Iterator<E> iterator, java.util.function.Function<? super E,? extends CharSequence> toStrFunc)追加Iterator中的元素到拼接器中<T> StrJoinerappend(Iterator<T> iterator)追加Iterator中的元素到拼接器中<T> StrJoinerappend(T[] array)追加数组中的元素到拼接器中<T> StrJoinerappend(T[] array, java.util.function.Function<T,? extends CharSequence> toStrFunc)追加数组中的元素到拼接器中intlength()长度
长度计算方式为prefix + suffix + content
此方法结果与toString().length()一致。StrJoinermerge(StrJoiner strJoiner)static @NotNull StrJoinerof(@NotNull StrJoiner joiner)根据已有StrJoiner配置新建一个新的StrJoinerstatic @NotNull StrJoinerof(CharSequence delimiter)使用指定分隔符创建StrJoinerstatic @NotNull StrJoinerof(CharSequence delimiter, CharSequence prefix, CharSequence suffix)使用指定分隔符创建StrJoinerStrJoinersetDelimiter(CharSequence delimiter)设置分隔符StrJoinersetEmptyResult(String emptyResult)设置当没有任何元素加入时,默认返回的字符串,默认""StrJoinersetNullMode(StrJoiner.NullMode nullMode)设置null元素处理逻辑StrJoinersetPrefix(CharSequence prefix)设置前缀StrJoinersetSuffix(CharSequence suffix)设置后缀StrJoinersetWrapElement(boolean wrapElement)设置前缀和后缀是否包装每个元素StringtoString()
-
-
-
构造器详细资料
-
StrJoiner
public StrJoiner(CharSequence delimiter)
构造- 参数:
delimiter- 分隔符,null表示无连接符,直接拼接
-
StrJoiner
public StrJoiner(Appendable appendable, CharSequence delimiter)
构造- 参数:
appendable- 字符串追加器,拼接的字符串都将加入到此,null使用默认StringBuilderdelimiter- 分隔符,null表示无连接符,直接拼接
-
StrJoiner
public StrJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)
构造- 参数:
delimiter- 分隔符,null表示无连接符,直接拼接prefix- 前缀suffix- 后缀
-
StrJoiner
public StrJoiner(Appendable appendable, CharSequence delimiter, CharSequence prefix, CharSequence suffix)
构造- 参数:
appendable- 字符串追加器,拼接的字符串都将加入到此,null使用默认StringBuilderdelimiter- 分隔符,null表示无连接符,直接拼接prefix- 前缀suffix- 后缀
-
-
方法详细资料
-
of
@NotNull public static @NotNull StrJoiner of(@NotNull @NotNull StrJoiner joiner)
根据已有StrJoiner配置新建一个新的StrJoiner- 参数:
joiner- 已有StrJoiner- 返回:
- 新的StrJoiner,配置相同
-
of
@Contract("_ -> new") @NotNull public static @NotNull StrJoiner of(CharSequence delimiter)使用指定分隔符创建StrJoiner- 参数:
delimiter- 分隔符- 返回:
- StrJoiner
-
of
@Contract("_, _, _ -> new") @NotNull public static @NotNull StrJoiner of(CharSequence delimiter, CharSequence prefix, CharSequence suffix)使用指定分隔符创建StrJoiner- 参数:
delimiter- 分隔符prefix- 前缀suffix- 后缀- 返回:
- StrJoiner
-
setDelimiter
public StrJoiner setDelimiter(CharSequence delimiter)
设置分隔符- 参数:
delimiter- 分隔符- 返回:
- this
-
setPrefix
public StrJoiner setPrefix(CharSequence prefix)
设置前缀- 参数:
prefix- 前缀- 返回:
- this
-
setSuffix
public StrJoiner setSuffix(CharSequence suffix)
设置后缀- 参数:
suffix- 后缀- 返回:
- this
-
setWrapElement
public StrJoiner setWrapElement(boolean wrapElement)
设置前缀和后缀是否包装每个元素- 参数:
wrapElement- true表示包装每个元素,false包装整个字符串- 返回:
- this
-
setNullMode
public StrJoiner setNullMode(StrJoiner.NullMode nullMode)
设置null元素处理逻辑- 参数:
nullMode- 逻辑枚举,可选忽略、转换为""或转换为null字符串- 返回:
- this
-
setEmptyResult
public StrJoiner setEmptyResult(String emptyResult)
设置当没有任何元素加入时,默认返回的字符串,默认""- 参数:
emptyResult- 默认字符串- 返回:
- this
-
append
public <T> StrJoiner append(T[] array)
追加数组中的元素到拼接器中- 类型参数:
T- 元素类型- 参数:
array- 元素数组- 返回:
- this
-
append
public <T> StrJoiner append(Iterator<T> iterator)
追加Iterator中的元素到拼接器中- 类型参数:
T- 元素类型- 参数:
iterator- 元素列表- 返回:
- this
-
append
public <T> StrJoiner append(T[] array, java.util.function.Function<T,? extends CharSequence> toStrFunc)
追加数组中的元素到拼接器中- 类型参数:
T- 元素类型- 参数:
array- 元素数组toStrFunc- 元素对象转换为字符串的函数- 返回:
- this
-
append
public <E> StrJoiner append(@NotNull @NotNull Iterable<E> iterable, java.util.function.Function<? super E,? extends CharSequence> toStrFunc)
追加Iterator中的元素到拼接器中- 类型参数:
E- 元素类型- 参数:
iterable- 元素列表toStrFunc- 元素对象转换为字符串的函数- 返回:
- this
-
append
public <E> StrJoiner append(Iterator<E> iterator, java.util.function.Function<? super E,? extends CharSequence> toStrFunc)
追加Iterator中的元素到拼接器中- 类型参数:
E- 元素类型- 参数:
iterator- 元素列表toStrFunc- 元素对象转换为字符串的函数- 返回:
- this
-
append
public StrJoiner append(CharSequence csq)
- 指定者:
append在接口中Appendable
-
append
public StrJoiner append(CharSequence csq, int startInclude, int endExclude)
- 指定者:
append在接口中Appendable
-
append
public StrJoiner append(char c)
- 指定者:
append在接口中Appendable
-
length
public int length()
长度
长度计算方式为prefix + suffix + content
此方法结果与toString().length()一致。- 返回:
- 长度,如果结果为
null,返回-1
-
-