navrsalemile
Programmer
Hi all,
public class Test {
public String[] getSJ()
{
String[] jg;
String[] jig;
String[] result;
StringBuffer buf = new StringBuffer();
int i;
int j;
int k = -1;
jg = {"g1", "g2"};
for( i=0; i < jg.length; i++ )
{
jig = {"1", "2", "3"};
for( j=0; i < jig.length; j++, k++ )
{
buf.append( jg ).append( ":" );
buf.append( jig[j] ).append( ":" );
buf.append( Date() );
result[k] = buf.toString();
buf = null;
}
}
return result;
}
}
I want to add to result string array by assigning from buf which is StringBuffer in a loop. But what happens after buf = null??
Will the added String be gone?
Or should I just do:
buf = "";
and continue with the loop and the string objects will be preserved? But isn't result just an array of references?
Many thanks,
public class Test {
public String[] getSJ()
{
String[] jg;
String[] jig;
String[] result;
StringBuffer buf = new StringBuffer();
int i;
int j;
int k = -1;
jg = {"g1", "g2"};
for( i=0; i < jg.length; i++ )
{
jig = {"1", "2", "3"};
for( j=0; i < jig.length; j++, k++ )
{
buf.append( jg ).append( ":" );
buf.append( jig[j] ).append( ":" );
buf.append( Date() );
result[k] = buf.toString();
buf = null;
}
}
return result;
}
}
I want to add to result string array by assigning from buf which is StringBuffer in a loop. But what happens after buf = null??
Will the added String be gone?
Or should I just do:
buf = "";
and continue with the loop and the string objects will be preserved? But isn't result just an array of references?
Many thanks,