Java Collection class & methods
Greetings. I've been growing into Java since my last post on JavaForums. I think I finally get the basics of the language.
Now, I'm facing efficiency problems. I have several solutions to the same problem, but I don't know which is better. Mainly becuase java.util.AbstractCollection offers such a variety of data structures.
Below, I'll describe what I pretend to achieve and what structures and methods I'm using to do so. I would appreciate if more experienced programmers give their insight on the matter.
Data structure 1:
A collection of non-repeated elements that must always be sorted accordingly to a given attribute. Elements are consumed from lowest to greatest. Removal of an element happens both on its consumption and determined by the program flow.
I'm using PriorityQueue with Comparable; offer() to "insertion sort" an element in the list; poll() to consume; and remove() to removal due to program flow.
Data structure 2:
A collection of non-repeated elements from which it must be sometimes known the 5 with a greatest given attribute. Removal of an element is due to program flow.
I'm using LinkedList; add() to insert an element in the end of list; remove(Object o) to remove. Manually sort the 5 greatest.
Data structure 3:
A collection of non-repeated elements without any kind of sort. Insertion may try to add a repeated element, in which case elements with greater index are removed.
I'm using LinkedList; add() to insert an element in the end of list; remove(int index) inside a while() to remove elements with greater index.
What do you think? Are there more efficient approaches?
Thanks in advance.