Results 1 to 3 of 3
  1. #1
    box2box's Avatar
    box2box is offline Member
    Join Date
    Apr 2010
    Rep Power

    Default 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.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    efficiency problems.
    Can you describe your problems in more detail?

  3. #3
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Rep Power

Similar Threads

  1. Calling methods into another class? Help please!
    By javanator in forum New To Java
    Replies: 1
    Last Post: 03-20-2010, 06:19 PM
  2. How can I call abstract class methods from another class
    By srinivas2828 in forum New To Java
    Replies: 13
    Last Post: 03-12-2010, 02:33 PM
  3. know the class coming under the collection api in java
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 07:10 AM
  4. Concept about methods of Class
    By s021126 in forum New To Java
    Replies: 9
    Last Post: 08-25-2009, 04:23 AM
  5. Replies: 0
    Last Post: 01-02-2008, 01:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts