V
Veleek
Hello,
I'm looking to create a kind of grid with each time being made up of a
kind of bag (I was using ArrayLists) that I can use to add a series of
object do depending on their location in a field.
I'm using this method so I can efficiently determine which objects are
near to each other. I'd like to use this method to keep the algorithm
to O(n) as opposed to O(n^2).
What I've tried to do is make a 2-d array of ArrayLists that I
implemented with:
ArrayList[][] grid = new ArrayList[40][40];
Unfortunately, The arraylists don't seem to initialize themselves and I
just get a 2D Array of nulls. I've tried just making a 1D Array of
ArrayLists and it does the same thing and doesn't initialize.
Does anybody have any suggestions? I would also be willing to accept
any other ideas for maintaining a grid style listing like this. Though
keep in mind that the object will be moving around so it needs to be
possible to add and remove items from the Boxes/Bags. Please let me
know what you think.
- Ben Randall
I'm looking to create a kind of grid with each time being made up of a
kind of bag (I was using ArrayLists) that I can use to add a series of
object do depending on their location in a field.
I'm using this method so I can efficiently determine which objects are
near to each other. I'd like to use this method to keep the algorithm
to O(n) as opposed to O(n^2).
What I've tried to do is make a 2-d array of ArrayLists that I
implemented with:
ArrayList[][] grid = new ArrayList[40][40];
Unfortunately, The arraylists don't seem to initialize themselves and I
just get a 2D Array of nulls. I've tried just making a 1D Array of
ArrayLists and it does the same thing and doesn't initialize.
Does anybody have any suggestions? I would also be willing to accept
any other ideas for maintaining a grid style listing like this. Though
keep in mind that the object will be moving around so it needs to be
possible to add and remove items from the Boxes/Bags. Please let me
know what you think.
- Ben Randall