String split 注意事项

在做588. Design In-Memory File System时遇到 split 函数的坑。

1.  String[]  strs=  ”/a/b/c“.split("/") 得到的是 strs=   ["","a","b","c"] 四个字符串,所以应该忽略第一个空字符串

2.  String[]  strs=  ”/“.split("/") 得到的是 strs.length = 0 ,所以对 "/" 要单独处理

猜你喜欢

转载自www.cnblogs.com/keepAC/p/10357086.html