Scanner vs. StringTokenizer vs. String.Split
来源:互联网 发布:计算天数的软件 编辑:程序博客网 时间:2024/06/15 20:25
从stack overflow上面看到java输入的对比答案,附链接:
http://stackoverflow.com/questions/691184/scanner-vs-stringtokenizer-vs-string-split
They're essentially horses for courses.
Scanner
is designed for cases where you need to parse a string, pulling out data of different types. It's very flexible, but arguably doesn't give you the simplest API for simply getting an array of strings delimited by a particular expression.String.split()
andPattern.split()
give you an easy syntax for doing the latter, but that's essentially all that they do. If you want to parse the resulting strings, or change the delimiter halfway through depending on a particular token, they won't help you with that.StringTokenizer
is even more restrictive thanString.split()
, and also a bit fiddlier to use. It is essentially designed for pulling out tokens delimited by fixed substrings. Because of this restriction, it's about twice as fast asString.split()
. (See my comparison ofString.split()
andStringTokenizer
.) It also predates the regular expressions API, of whichString.split()
is a part.
You'll note from my timings that String.split()
can still tokenizethousands of strings in a few milliseconds on a typical machine. In addition, it has the advantage overStringTokenizer
that it gives you the output as a string array, which is usually what you want. Using anEnumeration
, as provided by StringTokenizer
, is too "syntactically fussy" most of the time. From this point of view,StringTokenizer
is a bit of a waste of space nowadays, and you may as well just useString.split()
.
0 0
- Scanner vs. StringTokenizer vs. String.Split
- Scanner vs. StringTokenizer vs. String.Split
- String.split VS StringTokenizer
- StringTokenizer类与String.split()的区别
- String.split()和StringTokenizer(string str,string delim)构造函数
- String VS StringBuffer VS StringBuilder
- C# string vs String
- String的substring、split, StringTokenizer 截取字符串性能比较
- String的substring、split, StringTokenizer 截取字符串性能比较
- String的substring、split,外加StringTokenizer三者截取字符
- String 的 split、subString,外加StringTokenizer之性能比较
- String类的split()方法与StringTokenizer方法
- string+vs String.format ,append vs AppendFormat
- <string>VS<string.h>VS<cstring>
- String(+) vs StringBuffer(append)
- String vs StringBuilder
- string VS char
- StringBuffer VS String
- POJ - 1458 Common Subsequence(最长公共子序列)
- 浅析 PHP 官方自动化测试方法
- POJ - 2533 Longest Ordered Subsequence(最长上升子序列)
- javascript图片随滚动条置顶
- 自定义RadioButton
- Scanner vs. StringTokenizer vs. String.Split
- sourceinsight 无法搜索类似 .s .S .kconfig文件的解决办法
- 【软件工程作业01】
- https 基础
- hdu5249KPI【treap】
- 【Odoo】XML_RPC访问Odoo数据库
- Java实现UML中的五种关系
- HttpUnit Ajax处理
- POJ - 3616 Milking Time(DAG)