码迷,mamicode.com
首页 > 编程语言 > 详细

java的split的坑,会忽略空值

时间:2015-10-28 09:22:39      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

	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了

java的split的坑,会忽略空值

标签:

原文地址:http://www.cnblogs.com/hark0623/p/4916264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!