> 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
> 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"
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