我自己写的速度是它的40% :)
 ------------------------------------------------------
           我们还年轻牛奶会有的奶牛也会有的 
             可天天在 csdn 混这些会有吗 ??

解决方案 »

  1.   

    zez(思恩 为老婆多挣钱 鹤清风) ( ) :
    用JProfiler测的?
      

  2.   

    看我的:
    public static String replace(String s, String oldString, String newString)
    {
        if(s == null)
            throw new NullPointerException("source String cannot be null");
        if(oldString == null)
            throw new NullPointerException("old String cannot be null");
        if(newString == null)
            throw new NullPointerException("new String cannot be null");
        if(oldString.length() == 0)
            throw new IllegalArgumentException("old String cannot be empty");    StringBuffer result = new StringBuffer();    int start = 0;
        int end = s.indexOf(oldString);
        while(end != -1)
        {
            result.append(s.substring(start, end));
            result.append(newString);
            start = end + oldString.length();
            end = s.indexOf(oldString, start);
        }
        result.append(s.substring(start, s.length()));    return result.toString();
    }