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 
NullPointerException - if regex is null
Since: 
1.4 
See Also:
PatternAPI上是这么说的,可能是和数组写发有关吧

解决方案 »

  1.   

    你可以看一下API中关于regular expression的说明
    "Predefined character classes
    .  Any character (may or may not match line terminators) "
    此处“.”和“,”不同,“”表示的不是字符“.”而是表示line terminators
    而“,”则表示字符“,”
    如果你在程序中引用“,”,代码如下
    就不会有问题
    public class Test1
    {
    public static void main(String[] args)
    {
    String str = "faasdf,faf";
    String[] s = str.split(",");
    System.out.println(s[0]);
    }
    }
      

  2.   

    对,谢谢关注,我当时看,确实是may or may not match line terminators,会有问题,但是用split("[.]")就可以达到目的。