java的split的坑,会忽略空值

	String test = "@@@@";
	String[] arrayTest = test.split("\\@");
	System.out.println(arrayTest.length);

输出为0,split为忽略空值,如果要想取得正确的值,需要:

    String test = "@@@@";
    String[] arrayTest = test.split("\\@",-1);
    System.out.println(arrayTest.length);

这时输出就是5了

posted @ 2015-10-28 08:55  HarkLee  阅读(5859)  评论(0编辑  收藏  举报