Results 1 to 3 of 3
Thread: Java Collection class & methods
- 05-25-2010, 07:10 PM #1
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.
- 05-26-2010, 12:33 AM #2efficiency problems.
- 05-26-2010, 01:51 AM #3Senior Member
- Join Date
- Mar 2010
- Rep Power
- By javanator in forum New To JavaReplies: 1Last Post: 03-20-2010, 07:19 PM
- By srinivas2828 in forum New To JavaReplies: 13Last Post: 03-12-2010, 03:33 PM
- By javastuden in forum New To JavaReplies: 1Last Post: 11-24-2009, 08:10 AM
- By s021126 in forum New To JavaReplies: 9Last Post: 08-25-2009, 04:23 AM
- By searcher34 in forum JDBCReplies: 0Last Post: 01-02-2008, 02:52 PM