Java中split方法的细节问题。
2011-03-16 10:42
411 查看
先看一段代码:
你会觉得长度应该不是1,那是为什么呢?
看一下jdk中关于方法的说明。
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument
The string "boo:and:foo", for example, yields the following results with these expressions:
发现红色的这句话很关键“结尾的空白字符串会被略去,不会包含在返回的结果数组中。
所以开始的代码返回的长度为1.
String a="a::::::"; String[] str=a.split(":"); // 返回长度为1 System.out.println(str.length);
你会觉得长度应该不是1,那是为什么呢?
看一下jdk中关于方法的说明。
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
splitmethod 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" } |
发现红色的这句话很关键“结尾的空白字符串会被略去,不会包含在返回的结果数组中。
所以开始的代码返回的长度为1.
相关文章推荐
- 关于JAVA中split方法使用竖线异常的问题
- 细节问题:String 的split方法
- java split 方法边界问题
- java使用String.split方法时要注意的问题
- 关于java中String类型的split方法问题
- java中String对象的split方法不能得到空字符串的问题
- java.lang.String的substring、split方法引起的内存问题
- 关于Java中split方法对空字符串处理问题
- JAVA String操作split方法,以|作为分隔符切割问题
- java使用String.split方法时遇到的问题(转载)
- Java Split()方法按点(.)切分注意细节
- 关于Java中split方法对空字符串处理问题
- java.lang.String的substring、split方法引起的内存问题
- Java split()方法使用注意问题
- 转: 关于Java中split方法对空字符串处理问题
- java中static方法的使用问题
- java设置一段代码执行的超时时间的简单方法 间接实现获取Connection超时问题
- Java字符串分割方法split()的功能以及使用方法的详细介绍!
- java 解决Eclipse挂掉问题的方法
- JAVA 关于abstract 方法里参数的问题