splitByWholeSeparatorPreserveAllTokens和split之间的区别 [英] Difference between splitByWholeSeparatorPreserveAllTokens and split

查看:3198
本文介绍了splitByWholeSeparatorPreserveAllTokens和split之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

StringUtils.splitByWholeSeparatorPreserveAllTokens()String.split()有什么区别?

使用splitByWholeSeparatorPreserveAllTokens,我们可以限制数组中返回的参数的数量.这是唯一的区别吗?

解决方案

java.lang.String.split();
用法: 此方法返回的数组包含此字符串的每个子字符串,该子字符串由与给定表达式匹配的另一个子字符串终止或由字符串的结尾终止.数组中的子字符串按照它们在此字符串中出现的顺序排列.如果表达式与输入的任何部分都不匹配,则结果数组只有一个元素,即此字符串.

org.apache.commons.lang.StringUtils.splitPreserveAllTokens();
用法: 将提供的文本拆分为指定分隔符的数组,并保留所有标记,包括由相邻分隔符创建的空标记.这是使用StringTokenizer的替代方法.

更多信息: kickjava_src_apache_StringUtils

String.split()使用最后的类Pattern进行拆分.

Pattern.compile(regex).split(this , limit);

StringUtils中的

使用自己的方法splitWorker(String str, char separatorChar, boolean preserveAllTokens),这是针对2.0(JDK1.4)的性能调整.

What is the difference between StringUtils.splitByWholeSeparatorPreserveAllTokens() and String.split()?

With splitByWholeSeparatorPreserveAllTokens, we could limit the number of parameters that are returned in an array. Is this the only difference?

解决方案

java.lang.String.split();
Usage: The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

org.apache.commons.lang.StringUtils.splitPreserveAllTokens();
Usage: Splits the provided text into an array, separator specified, preserving all tokens, including empty tokens created by adjacent separators. This is an alternative to using StringTokenizer.

Read more: kickjava_src_apache_StringUtils

and String.split() uses the final class Pattern to split.

Pattern.compile(regex).split(this , limit);

in StringUtils uses splitWorker(String str, char separatorChar, boolean preserveAllTokens) , it's own method, which is a Performance tune for 2.0 (JDK1.4).

这篇关于splitByWholeSeparatorPreserveAllTokens和split之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆