This discussion is archived
1 2 3 4 Previous Next 47 Replies Latest reply: Feb 6, 2010 11:42 PM by 807580 RSS

Fastest Iterating data structure

807580 Newbie
Currently Being Moderated
Forgetting about the semantics about list and set, purely from iteration point of view, which data structure class would give fastest iteration?
  • 1. Re: Fastest Iterating data structure
    796440 Guru
    Currently Being Moderated
    That question is meaningless.

    The only way to get an answer is to test it for yourself. And then your answer will only apply to the particular version, JVM implementer, and OS an which you run your test. And the difference between the best and the worst will be completely negligible in all but the most bizarre corner cases.

    So if you're asking just for curiosity's sake, your question has been completely answered, and you are now satisfied.

    If you have an actual use case where this matters, you'll need to provide details about your use case and clarify exactly what you mean by "fastest iterating".

    Also note that, even if List were to iterate 1000 times faster than Set (whatever that means), if you need what Set offers and List doesn't--no duplicates--then you'll want to use Set anyway. That is, your "forget about semantics" comment is a bogus requirement.
  • 2. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    its not as stupid as it sounds to you. What I want to know that forgetting that i want duplicates or not, purely from iteration point of view I want to know which datastructure would give me fastest iteration over its collection of objects?
  • 3. Re: Fastest Iterating data structure
    796440 Guru
    Currently Being Moderated
    javanewbie80 wrote:
    its not as stupid as it sounds to you.
    Yes, it absolutely, 100% is.
    What I want to know that forgetting that i want duplicates or not, purely from iteration point of view I want to know which datastructure would give me fastest iteration over its collection of objects?
    This is no different from your first post. Therefore, every single word from my first response stands.
  • 4. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    its ok if you are not understanding the question.
  • 5. Re: Fastest Iterating data structure
    796440 Guru
    Currently Being Moderated
    javanewbie80 wrote:
    its ok if you are not understanding the question.
    From reply 1:

    >
    So if you're asking just for curiosity's sake, your question has been completely answered, and you are now satisfied.

    If you have an actual use case where this matters, you'll need to provide details about your use case and clarify exactly what you mean by "fastest iterating".
  • 6. Re: Fastest Iterating data structure
    796440 Guru
    Currently Being Moderated
    javanewbie80 wrote:
    its ok if you are not understanding the question.
    But I promise you, the lack of understanding is not on my end.

    I know you think I'm just being an arrogant, obnoxious vas deferens, but I actually do know what I'm talking about here. You need to either supply details about the context in which this matters, and support for why it matters, or else accept that your question is misguided.
  • 7. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    anyone??
  • 8. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    you need to listen to jverd. your question doesnt make sense.
    What I want to know that forgetting that i want duplicates
    huh? THEN YOU WOULDNT USE SET.
    there is a reason why there are Stack, Queue, ArrayList, LinkedList, Set, Vector, Tree etc etc.
    they may be "slower" in one context but "faster" in another.
    for example, linkedlist has "faster" random insertion but arraylist has "faster" random access.

    which is better a bee or a Boeing? it would all depend on whether youre moving pollen or people.
  • 9. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    lets say i have a collection of 1000 objects which does not have duplicates. Which data structure should i use to store them so that when i iterate over them I should get fastest(or lowest) iteration time....
  • 10. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    javanewbie80 wrote:
    anyone??
    every jdk should come with the library source. feel free to peruse how List and Set implement Iterable interface.
    (which is silly because different Lists and different Sets will implement it differently)
  • 11. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    javanewbie80 wrote:
    lets say i have a collection of 1000 objects which does not have duplicates. Which data structure should i use to store them so that when i iterate over them I should get fastest(or lowest) iteration time....
    Oh ok, I understand now. I have checked and I found out that it is a List. Bye.
  • 12. Re: Fastest Iterating data structure
    jwenting Journeyer
    Currently Being Moderated
    A HashSet could still be faster. He has no duplicates, but does he want to enforce that fact on the Collection (which would require a List) or is it a natural result of some other part of his process?
    Is the order of elements in the Collection (and thus the order in which they're returned during iteration) relevant or not?
  • 13. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    jwenting wrote:
    A HashSet could still be faster...
    (i was actually just being dismissive.)
  • 14. Re: Fastest Iterating data structure
    807580 Newbie
    Currently Being Moderated
    the order of the elements is not relevant and this collection of objects would be a result of some database operation and as a business rule there would not be any duplicates, therefore a list and set both would suffice. I guess Hashset would be faster for iteration than arraylist, but I feel linkedhasSet would be faster than hashset for iteration ..What you think? let me know....
1 2 3 4 Previous Next