So, simple question that seems to be baffling me. I have a series of ArrayList because they need to be expandable. Now, I would like to be able to pull the nth object from each one with a simple for loop.
public ArrayList<String> name = new ArrayList<String>();
public ArrayList<Integer> stamina = new ArrayList<Integer>();
public ArrayList<Integer> heart = new ArrayList<Integer>();
public ArrayList<Integer> intel = new ArrayList<Integer>();
public ArrayList<Integer> speed = new ArrayList<Integer>();
I'll be adding/pulling information from these later in my code, so I would like it to be easily accessible via a single 2D array. With something like,
racerInfo[][] = { name, stamina, heart, intel, speed };
Then if I want information for, say, racer number 7
for ( int i=0; i<=racerInfo.length - 1; i++ ) {
System.out.println(racerInfo[i][7]);
}
How would I go about setting up the racerInfo field? I can't seem to figure out the right setup. If you have any better suggestions for the rest I am completely open as I am still very new to this and just attempting to cobble something together that works.
RacerInfoinstead of an array of lists. Also - a bit nit-picky - Try to create collections against their interfaces, not there implementations (List list = new ArrayList())