Java data type problem -
I am working with the matrix in java. (Another story :))
I want to read a CSV file and store it in a variable. I'll manipulate the values then store it in a CSV file. I used STRING as the data type but if it is like 500 columns in the CSV file it hits my program speed :( I think this good data What type of data can I use to store temporary stores in long text?
If my question is not clear, then please ask questions. The
PS: I am reading a row and storing it in this type of variable
string str; str + = reading line by CD line ;
There is a loop here
string for lessM = ""; (int kk = 0; kk & lt; w2.getRowDimension (); kk ++) {for (int jj = 0; jj & lt; w2.getColumnDimension (jg ++) {reduM + = Double.toString (reduceMatrix [kk] [jj]);} println ( "\ R \ n");}
use a StringBuilder
(or StringBuffer
augue If you are using 'Java 1.5 or above):
StringBuilder builder = new StringBuilder (; (For integer KK = 0;) K.K. & Lt; W2.getRowDimension (); KK ++) for {int jj = 0; jj & lt; w.2.gate columnement (); jg ++} {builder.epend (low matrix [k-k] [jj]); }}
For each walk of this two loops, avoid making a new (and fast) string.
However, a comma or line - breaks into this code - I doubt actually wants something like this:
StringBloulder Builder = New stringbilder (); {For (int jj = 0; jj & lt; w2.getColumnDimension (); jj ++) {builder.append (reduceMatrix [kk] [jj]) (; kke & lt; w2.getRowDimension ) .append (",") for KK ++ integer KK = 0); } Builder.append ("\ n"); // whatever line terminator you want}
Note that at the end of each line an extra comma will be left - tell me how you want to remove it.
See why it can make a big difference in your running time (note that this is an old article about StringBuilder
instead of StringBuilder < / Code> Talking - afterwards, there is an unsyncised version of the former)
Comments
Post a Comment