在数据库取出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("&","&"))+"</title>\n" +
"<link>"+ch.toCode(collection[i][2].replaceAll("&","&"))+"</link>"+
"<description><![CDATA["+stb.toString().replaceAll("&","&")+"]]></description> \n" +
"</item>\n");
stb.delete(0,stb.length());
}
请问有更快的办法吗?
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("&","&"))+"</title>\n" +
"<link>"+ch.toCode(collection[i][2].replaceAll("&","&"))+"</link>"+
"<description><![CDATA["+stb.toString().replaceAll("&","&")+"]]></description> \n" +
"</item>\n");
stb.delete(0,stb.length());
}
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");
}
在Servlet生成就很慢啊~
另外,尽量使用append,不要在append中使用“+”进行连接
"<title>"+ch.toCode(collection[i][3].replaceAll("&","&"))+"</title>\n" +
"<link>"+ch.toCode(collection[i][2].replaceAll("&","&"))+"</link>"+
"<description><![CDATA["+stb.toString().replaceAll("&","&")+"]]></description> \n" +
"</item>\n")这一点:呵呵~~~ 以后注意了!
我看到在StringBuffer里面用" + " 我就生气!
没道理啊~~~