ArrayList<String[]> writtenClasses = new ArrayList<String[]>();
// usually there is functional code here that populates
// ArrayList<String[]> writtenClasses with variably 3000
// String[] objects always of exactly 8 lines each
ArrayList<String> processedClasses = new ArrayList<String>();
for(String[] classLines: writtenClasses)
{
for(String classLine: classLines)
{
processedClasses.add(classLine);
}
}
String result = "";
for(String fileLine: processedClasses)
{
result += fileLine + "\n";
}
My code is above. It works fine and produces exactly the result I want, just slowly. It takes about 10ms per item of ArrayList writtenClasses which is okay until I give it bigger jobs. I suspect that there is something there to do with ArrayLists that is taking so long, but timing and printing to console job stats after each run revealed little.
This above code is an adaptation of earlier code in hopes to improve efficiency. It does so by about 4%. The below code is the old method I used which takes just a little longer than the above.
for(String[] classLines: writtenClasses)
{
for(String classLine: classLines)
{
result += classLine + "\n";
}
writtenClasses.set(writtenClasses.indexOf(classLines), null);
}
I do writtenClasses.set(writtenClasses.indexOf(classLines), null);
merely for the purposes of memory efficiency, and my stats show that it uses memory more efficiently with an undetectable amount of CPU effort.
This is my second question here on StackOverflow and i've done my best to follow the rules, but if i'm asking this badly or being inadvertently inconsiderate in some way, please, highlight that to me and i'll address that. :)