adding varibles to array and using Jlist
Hello
i want to add some variables to an array and i want to use for loop beacuase I have 500 varibles and i cant do this
Code :
names[350] = var;
names[351] = var;
names[352] = var;
names[353] = var;
this will take 500 lines so i want to use a for loop but i don't know how to add each variable to an element of the array.
Code :
private void List() {
String one = "Hello", two = "How", three = "Are", four = "You";
String[] names = new String[4];
names[0] = one;
names[1] = two;
names[2] = three;
names[3] = four;
/*
for(int i=0; i<names.length; i++) {
names[i] += one;
names[i] += two;
names[i] += three;
names[i] += four;
}*/
JList list = new JList(names);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSize(100, 100);
list.setLocation(100, 100);
ContentPane.add(list);
}
Re: adding varibles to array and using Jlist
Quote:
i want to add some variables to an array and i want to use for loop beacuase I have 500 varibles and i cant do this
I assume you mean the value of variables. Are variables given or you will have to create on your own?
From where is the value assigning to these variables?