简体   繁体   中英

what is the best way to create a matrix of array lists (array lists of objects) and how should I initialize it?

I want to create a matrix that contains 5 arrary list. each array list contains different objects but from the same types (they all Actors but every array list contains a different actor...) how should I initialize it? it's basically a game. I want to initialize every actor in the array lists with a position and the general matrix with all the actors/array lists.

create a matrix that contains 5 array lists

ArrayList[] matrix = new ArrayList[5];

each array list contains different objects but from the same types

matrix[0] = new ArrayList<MyCustomClass>();
matrix[0].add(new MyCustomClass(...));
matrix[0].add(new MyCustomClass(...));

how do i get to each actor later

// one way of getting the Actor object if you know 
matrix[0].get(index);the index

If you don't know the index, then you will have to traverse the arraylist and find the Actor you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM