much
better to create a StringBuffer of the required length than use the default
constructor.
It looks like you may not know the right length, but estimate high, every
time the StringBuffer expands it has to create a new character array and
copy the previous contents. It may be worthwhile
to iterate through your strings and add up the length beforehand, but probably
better to guess high.
db
____________________________________________________-----Original Message-----
From: Allan Wick [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 20, 2003 10:34 AM
To: JDJList
Subject: [jdjlist] RE: Slow: string += stringUse a StringBuffer.StringBuffer theBuffer = StringBuffer();for (int r = 0; r < selected.length; r++)
{theBuffer.append( rowdata[r] );}String output = theBuffer.toString();Something like that...-Al Wick____________________________________________________-----Original Message-----All:
From: Roger Lacroix [mailto:[EMAIL PROTECTED]]
Sent: Sunday, January 19, 2003 5:20 PM
To: JDJList
Subject: [jdjlist] Slow: string += string
I have my cells of a table defined as Object[][]. In my program, I added the ability for the user to select rows of the table to copy to the system clipboard (i.e. copy / cut / paste functionality).
Depending on what the user is viewing, there could be 400 rows by 2000 columns.
i.e. Object[][] xx = new Object[400][2000];
Say the user selects 20 rows, then I need to combine 40000 cells (20 * 2000). I have done every trick that I can think of, but it still is not as fast as I would expect. Right now I combine each row into a string then I combine each row-string each the final string.
Here is my current code:
String[] rowData = new String[selected.length];
for (int r = 0; r < selected.length; r++)
{
ptr = selected[r];
rowData[r] = msgCells[ptr][1].toString();
for(int c = 2; c < endColumn; c++)
{
if (msgCells[ptr][c] != null)
{
rowData[r] += msgCells[ptr][c].toString();
}
}
}
for (int r = 0; r < selected.length; r++)
{
tempClipboard += rowData[r];
}
Does anyone out there in Java land have a tip / trick /snippet of code to quickly & efficiently combine a large number of objects into a SINGLE string.
Thanks to all.
later
Roger Lacroix
Enterprise Architect
Capitalware Inc.
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
Be respectful! Clean up your posts before replying
____________________________________________________
