I have a large codebase (written by me) that uses the Stack data structure. This was used for convenience and I am using it as Stack sometimes or Vector/List some other times.
After a performance review however it was decided that we do not want to pay extra for the synchronization safety. I need now to replace this structure with a non-synchronized one (and it is mentioned a lot of times in the code).
I was happy to discover that Apache collections includes an ArrayStack which is exactly what I want (same as Java stack but non-synchronized). However this does NOT have generics as modern Java 5 code (which is what I use). And I am not going to convert my code to look like Java 1.4
So is there any other Java 5 compliant drop-in replacement for Java Stack or do I need to write my own?
Update:
I used LinkedList with tuned "pop"/"push" methods.
When you say "Java 5 compliant" - ArrayDeque<T>
didn't arrive until Java 6, but sounds like what you're after (using the Deque<T>
interface where appropriate, of course). You can use it as a stack when you want to, or a queue where that's more appropriate... just call the appropriate methods, basically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With