T
Thomas Hawtin
Vanessa said:I'ev a big problem. I've a program that handles with a orded set of object.
With this objects I've to
a)execute a LOT of random access
b) insert/remove from head and tail (not so frequently as the number of
operation (a) )
Do I have to use an ArrayList o LinkedList?
Suck it and see.
You should find a long LinkedList is absolutely terrible for random access.
Unfortunately ArrayList isn't cyclic, removing from the head will cost.
It probably wont cost as much as a random access on a long LinkedList.
Removing from the head of an array list, just involves a block move of
pointers. Making your way through a linked list involves accessing large
amounts of memory (whether randomly or sequentially will likely depend
upon GC algorithm).
If you do lots of inserts/removes on heads and tails separately, perhaps
you could get away with reversing the list from time to time or
inserting/removing a block at a time.
For small lists, you may find different results apply.
You might be able to find a CyclicArrayList implementation somewhere (or
write your own if it is important). Java 1.6 will have Deque and in
particular ArrayDeque, unfortunately neither support random access.
Tom Hawtin