在数据库取出1000条记录,,做循环取出大概400000字符,要35秒,,太慢了,
  请问有更快的办法吗?
  
  StringBuffer stb=new StringBuffer();
  StringBuffer stb2=new StringBuffer();  
  for (int i=0;i<collection.length&&!collection[0][0].equals("");i++)
      {
             stb.append(collection[i][4]+"<br>第一个收藏者 ");
             stb2.append("<item>\n" +
             "<title>"+ch.toCode(collection[i][3].replaceAll("&","&amp;"))+"</title>\n" +
             "<link>"+ch.toCode(collection[i][2].replaceAll("&","&amp;"))+"</link>"+
             "<description><![CDATA["+stb.toString().replaceAll("&","&amp;")+"]]></description> \n" +
             "</item>\n");
             stb.delete(0,stb.length());
     }

解决方案 »

  1.   

    用了<![CDATA[]]>还需要用replace把&代替成&amp;吗?
      StringBuffer stb2=new StringBuffer();  
      for (int i=0;i<collection.length&&!collection[0][0].equals("");i++)
          {
                 stb2.append("<item>\n" +
                 "<title><![CDATA["+ch.toCode(collection[i][3])+"]]></title>\n" +
                 "<link><![CDATA["+ch.toCode(collection[i][2])+"]]></link>"+
                 "<description><![CDATA["+collection[i][4]+"<br>第一个收藏者 "+"]]></description> \n" +
                 "</item>\n");
         }
      

  2.   

    这个我用来生成xml的,,RSS浏览器浏览的。
    在Servlet生成就很慢啊~
      

  3.   

    用StringBuilder试试
    另外,尽量使用append,不要在append中使用“+”进行连接
      

  4.   

    stb2.append("<item>\n" +
    "<title>"+ch.toCode(collection[i][3].replaceAll("&","&amp;"))+"</title>\n" +
    "<link>"+ch.toCode(collection[i][2].replaceAll("&","&amp;"))+"</link>"+
    "<description>&lt;![CDATA["+stb.toString().replaceAll("&","&amp;")+"]]&gt;</description> \n" +
    "</item>\n")这一点:呵呵~~~ 以后注意了! 
    我看到在StringBuffer里面用" + " 我就生气!
    没道理啊~~~