Noob seeks to emulate javascript array

anyone have any suggestions for emulating this behavior described below?

I need a way to have an indexed list, which will store undefined indexes. Hashtable<Integer,blah> could do it, but the thing is that the integers are unordered. they aren't indexes.

The other way to describe it is an array of parking spaces, where the space can either be empty or have a car object in it. I'd also like to be able to reliably iterate from one end of the block to the other.

in code, I'd like to be able to do the following

JSArray<Car> parkingSpaces =new JSArray<Car>();

parkingSpaces.set(0,new Car("maybach") );

parkingSpaces.set(1,new Car("beemer") );

parkingSpaces.set(2,new Car("broken down gremlin") );

myWeirdCollection.remove(1);

for(int i = 0 ; i< myWeirdCollection.size();i++)

{

if(myWeirdCollection.get(i)==null)

{

println(i+" empty parking space!");

}

else

{

print(i+" "+myWeirdCollection.get(i) );

}

}

/*

output:

0 maybach

1 empty parking space!

2 broken down gremlin

*/

please forgive me if this has been covered. I'm having a tough time making my way around this huge library of documentation. I think I explored all the built in collections though. I'm still trying to think of a way to maybe subclass a hashtable or something.

[2032 byte] By [Mata] at [2007-11-27 6:57:33]
# 1

I don't quite get it, where did myWeirdCollection come from?

Based on your example, assuming that parkingSpaces and myWeirdCollection are supposed to be the same thing, you need an ArrayList:List<Car> parkingSpaces = new ArrayList<Car>();

parkingSpaces.add(new Car("maybach"));

parkingSpaces.add(new Car("beemer"));

parkingSpaces.add(new Car("broken down gremlin"));

parkingSpaces.set(1, null);

for (Car c : parkingSpaces) {

if (c == null) {

System.out.println("empty parking space!");

} else {

System.out.println(c);

}

}

dwga at 2007-7-12 18:34:52 > top of Java-index,Core,Core APIs...
# 2
Thanks dwgyour example works. I believe I ruled out ArrayList because because I there was an error in the code I used to audition it. (I was using .set() rather than .add())As you can imagine, this makes ArrayList nine billion times more useful.
Mata at 2007-7-12 18:34:52 > top of Java-index,Core,Core APIs...