Java split
来源:互联网 发布:skycc营销软件系统 编辑:程序博客网 时间:2024/05/16 23:35
String split 用得太多了,但是今天编代码时发现好几个同事犯错了! 好奇心来了,顺便测试了群里一帮人,90%出错了,呵呵! 有兴趣你自己也测试一下吧! 答案在文后!
1.
String st3 = "";
System.out.println(st3.split("\\s+").length);
打印多少呢?
2.
String st2 = " hi, Marty";
System.out.println(st2.split("\\s+").length);
2.
String st4 = " ";
System.out.println(st4.split("\\s+").length);
大家参考一下文档或者文章http://shukuiyan.iteye.com/blog/1058672
split
public String[] split(String regex)
- Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument
split
method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.The string "boo:and:foo", for example, yields the following results with these expressions:
Regex Result :{ "boo", "and", "foo" }o{ "b", "", ":and:f" } - Parameters:
regex
- the delimiting regular expression- Returns:
- the array of strings computed by splitting this string around matches of the given regular expression
- Throws:
PatternSyntaxException
- if the regular expression's syntax is invalid- Since:
- 1.4
- See Also:
Pattern
- 答案: 1, 3, 0
- java split
- java-----------------split
- java split “.”
- java split
- java split
- java split
- java split
- Java split
- java split
- java split
- java split
- java split
- java split
- java split()
- java split
- JAVA--Split
- java split
- java split
- HDU1597
- Hadoop-CDH4的部署包的文件结构
- 巧用好官方API学好EXTJS
- 价格战草草收场 电商巨头空赚知名度赔了美誉度
- 第二次量产成功:KingSton DT 101 G2 8G的量产经历
- Java split
- IT项目管理工具
- 一起读nodejs(三)----模块(Modules)
- Editlog的接口规范设计文档(HDFS-1580:Add interface for generic Write Ahead Logging mechanism)
- 学习join用法
- 最短路径算法--Dijkstra算法,Bellmanford算法,Floyd算法,Johnson算法
- Remove '@override' annotation解决办法
- Codeforces Round #135 (Div. 2)
- Google Host