I'm trying to generate a variable number of arrayLists with a variable number of items within the list. This means that I can't use an array instead of an arrayList.
When generating a JLabel in an array, you use the for loop and say:
label[i]=new JLabel();
Is this possible for an arrayList?
I can't put up my code because it's to long but i'll give you the general idea: Within a txt, there are multiple objects, in this case, troops: longbowman, man at arms, knight... Each 1 shares the same stats (ArrayLists) but have different values for each one. I have it so that once the bufferedReader finishes with a troop, it sends all the arraylists to another class, and continues reading and overwriting the old troops stats (they are now stored in a different class). the problem is, how can the other class differentiate between the stats? This would be easy if the number of types of troops was constant, but, it isn't. So how can I do this?
Edit: here is a bit of the source code:
while ((text = reader.readLine()) != null) {
StringTokenizer troops = new StringTokenizer(text, "=");
String list = troops.nextToken();
String value = troops.nextToken();
else if (list.equals("Done")) {
troop trooper=new troop();
trooper.troopLoaded(kingdom,lord,troop,troopAmount,weapon,animal);
}
/////
troop class:
public void troopLoaded(ArrayList<String> kingdom,ArrayList<String> lord,ArrayList<String> troop,ArrayList<String>,troopAmount,ArrayList<String> weapon,ArrayList<String> animal) {
System.out.println(kingdom);
System.out.println(lord);
System.out.println(troop);
System.out.println(troopAmount);
System.out.println(weapon);
System.out.println(animal);
}
how do I give troop class the arraylists without over writing them in the troop class?