Pass variable into array

Hi,Just wonder wanna to know how do I use variable in array. As below: objstr = objstr + ", " + "\"EXPECTATION" + count + "\"";String[] colnamesg = {"PERSON_ID","EMPLOYEE_NUMBER","RATING","EVENT_ID","CREATOR_ID"+ objstr};I fail with above statement. pls
[298 byte] By [winwuna] at [2007-10-3 6:40:29]
# 1
> I fail with above statement. pls advise...I advise to tell us the error message, since I didn't see anything wrong.
CeciNEstPasUnProgrammeura at 2007-7-15 1:29:22 > top of Java-index,Java Essentials,New To Java...
# 2

> Hi,

>

> Just wonder wanna to know how do I use variable in

> array. As below:

>

> objstr = objstr + ", " + "\"EXPECTATION" + count +

> "\"";

> tring[] colnamesg =

> {"PERSON_ID","EMPLOYEE_NUMBER","RATING","EVENT_ID","CR

> EATOR_ID"+ objstr};

>

> I fail with above statement. pls advise...

you cannot instanciate an String array with a changing values,

use StringBuffer to resize strings at runtime

JosepTa at 2007-7-15 1:29:22 > top of Java-index,Java Essentials,New To Java...
# 3
> you cannot instanciate an String array with a> changing values,> use StringBuffer to resize strings at runtimeInteresting. I guess I have to tell that to my compiler.And how do you use StringBuffer instead of a String array?
CeciNEstPasUnProgrammeura at 2007-7-15 1:29:22 > top of Java-index,Java Essentials,New To Java...
# 4

> you cannot instanciate an String array with a changing values,

>use StringBuffer to resize strings at runtime

huh?

The code runs fine with a couple of added lines:

public static void main(String args[]) {

int count = 10;

String objstr = "SOMETHING";

objstr = objstr + ", " + "\"EXPECTATION" + count + "\"";

String[] colnamesg = {"PERSON_ID","EMPLOYEE_NUMBER","RATING","EVENT_ID","CREATOR_ID"+ objstr};

for (int i=0; i < colnamesg.length; i++) {

System.out.println (colnamesg[i]);

}

}

outputs:

PERSON_ID

EMPLOYEE_NUMBER

RATING

EVENT_ID

CREATOR_IDSOMETHING, "EXPECTATION10"

orbacha at 2007-7-15 1:29:22 > top of Java-index,Java Essentials,New To Java...
# 5
No, it still can't achieve what I want, what I'm trying to do is I want to add the "element" of an array. So from my example, I want to add "EXPECTATION10" as element. Due to the new element is dynamic, so I can't fix the string array elements. Kindly advise......
winwuna at 2007-7-15 1:29:22 > top of Java-index,Java Essentials,New To Java...
# 6

I am not sure what you are asking for.

However, based on few assumptions I guess this is what you wanted.

public static void main(String args[]) {

int count = 10;

String objstr = "";

objstr = "EXPECTATION" + count;

String[] colnamesg = {"PERSON_ID","EMPLOYEE_NUMBER","RATING","EVENT_ID","CREATOR_ID", objstr};

for (int i=0; i < colnamesg.length; i++) {

System.out.println (colnamesg[i]);

}

}

gives you this.

PERSON_ID

EMPLOYEE_NUMBER

RATING

EVENT_ID

CREATOR_ID

EXPECTATION10

praveendxa at 2007-7-15 1:29:22 > top of Java-index,Java Essentials,New To Java...