1 Star 0 Fork 454

鹏鹏大帅哥/bullshit-codes

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Split 780 Bytes
一键复制 编辑 原始数据 按行查看 历史
/**
* 字符串split使用场景比较频繁,此处有一个极易掉坑的操作
*
* @author shuzheng
* @date 2019/5/27
*/
public class Split {
public static void main(String[] args) {
String param1 = "1,2";
String param2 = "1,2,";
String param3 = ",1,2,";
System.out.println(param1.split(",").length);
System.out.println(param2.split(",").length);
System.out.println(param3.split(",").length);
}
/*
* 输出结果:
* 2
* 2
* 3
*
* 惊喜不惊喜?结尾的空字符串被丢弃,可使用重载方法 public String [] split (String regex, int limit) 中 limit 参数控制模式应用的次数,-1 则不会丢弃结尾空字符。
*/
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peishuaige/bullshit-codes.git
git@gitee.com:peishuaige/bullshit-codes.git
peishuaige
bullshit-codes
bullshit-codes
master

搜索帮助