Loop algorithm
I got the following code:
Vector
Vector<String> v =new Vector<String>();
for (int i = 0; i < 10000; ++i)// For example
{
v.add(str1 + str2 + str3);
}
where st1, str2 and str3 are strings that change through every iteration, so they can't be added from before.
The adding line is quite a performance killer, hprof:heap=sites returned me this:
SITES BEGIN (ordered by live bytes) Thu Jan 19 14:14:10 2006
percent live alloc'ed stack class
rankself accumbytes objsbytes objs trace name
1 12.77% 12.77%245248 3961 27040000 454000 305536 char[]
..............................................................................................................................
and
TRACE 305536:
java.lang.String.<init>(String.java:208)
java.lang.StringBuilder.toString(StringBuilder.java:431)
[The adding line]
Does anyone know whats wrong with that code, because in my program, the line is quite a performance killer. I already tried to build a StringBuffer and add it afterwards, but it didn't bring any improvement.
Does anybody know a suitable solution?
R. Hollenstein

