Search code examples
javacollectionsinsertion

Java random insert collection


I am considering using a Java collection that would work best with random insertions. I will be inserting a lot and only read the collection once at the end.

My desired functionality is adding an element at a specified index, anywhere between <0, current_length>. Which collection would be the most efficient to use?


Solution

  • Useful link for your reference: http://www.coderfriendly.com/wp-content/uploads/2009/05/java_collections_v2.pdf

    Not entirely sure how you will be reading the information post input (and how important it is to you). Hashmap or ArrayList would make sense depending on what you are looking to do. Also not sure if you are looking for something thread safe or not. Hope it helps.