I’m implementing an algorithm that will add strings at the end a collection and remove strings at the beginning. In rare cases I will perform random access remove to push it at the end. I’m mostly a C++ dev, and I’m not sure what will be good to use in my critical loop in java. I don’t think a java list will be well suited for the task. Sure it will work, but I’m already struggling with performance issues.
linked list? vector? suggestions?
I’d recommend using
ArrayDeque, which implementsQueueandDequeinterfaces but doesn’t implementList(which you probably won’t need):You also mentioned remove:
ArrayDequeprovides all methods you’ll need –addFirst(E e),addLast(E e),removeFirst().See also this question to know more about
ArrayDeque.P.S. And here is some collections benchmark from above link featuring
ArrayDeque,LinkedListandArrayListmentioned by others 😉