Package org.miaixz.bus.core.text
Class StringSplitter
- All Implemented Interfaces:
Serializable,Iterator<String>
字符串切分迭代器 此迭代器是字符串切分的懒模式实现,实例化后不完成切分,只有调用
ComputeIterator.hasNext()或遍历时才完成切分 此迭代器非线程安全- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStringSplitter(CharSequence text, TextFinder separatorFinder, int limit, boolean ignoreEmpty) 构造 -
Method Summary
Modifier and TypeMethodDescriptionprotected String计算新的节点,通过实现此方法,当调用ComputeIterator.hasNext()时将此方法产生的节点缓存,直到调用ComputeIterator.next()取出 当无下一个节点时,须返回null表示遍历结束voidreset()重置String[]toArray(boolean trim) 获取切分后的对象数组toList(boolean trim) 获取切分后的对象列表<T> List<T> 获取切分后的对象列表Methods inherited from class org.miaixz.bus.core.center.iterator.ComputeIterator
finish, hasNext, nextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
StringSplitter
public StringSplitter(CharSequence text, TextFinder separatorFinder, int limit, boolean ignoreEmpty) 构造- Parameters:
text- 文本,不能为nullseparatorFinder- 分隔符匹配器limit- 限制数量,小于等于0表示无限制ignoreEmpty- 是否忽略""
-
-
Method Details
-
computeNext
Description copied from class:ComputeIterator计算新的节点,通过实现此方法,当调用ComputeIterator.hasNext()时将此方法产生的节点缓存,直到调用ComputeIterator.next()取出 当无下一个节点时,须返回null表示遍历结束- Specified by:
computeNextin classComputeIterator<String>- Returns:
- 节点值
-
reset
public void reset()重置 -
toArray
获取切分后的对象数组- Parameters:
trim- 是否去除元素两边空格- Returns:
- 切分后的列表
-
toList
获取切分后的对象列表- Parameters:
trim- 是否去除元素两边空格- Returns:
- 切分后的列表
-
toList
获取切分后的对象列表- Type Parameters:
T- 元素类型- Parameters:
mapping- 字符串映射函数- Returns:
- 切分后的列表
-