今天莫名其妙的又做了一下leetcode上面的第一题,是简单的字符串逆序输出问题.下面是我处理的代码: public String reverseWords(String s) { if(s == null) return new String(""); StringBuffer fir = new StringBuffer(s); if(fir.length() == 0) return new String(""); while(fir.length() !=
项目中我用到了字符串的split()方法,为这种方法的方便称赞,可是程序在测试的时候出现的问题折腾了我好久,原来在使用的时候存在着以下几个需要注意的地方. 本来使用split()方法是判断String的数量,结果这么的不靠谱,最后换成了hashset动态添加字符串,然后求hashset.size()的方法得到字符串的个数解决的.... Java代码 public String[] split(String regex, int limit) split函数是用于使用特定的切割符(regex)
public class SplitDemo { public static void main(String[] args) { String a = "abcooob"; String[] as = a.split("o"); System.out.println(as.length); } } 运行结果是 4abc b 因为分割成{"abc","
function split(str,sp) local result = {} local i = 0 local j = 0 local num = 1 local pos = 0 while true do i , j = string.find(str,sp,i+1) if i == nil then if num ~=1 then result[num] = string.sub(str,pos,string.len(str)) end break end result[num] =