HashMap vs TreeMap

Discussion in 'Java' started by Ahmed Moustafa, Aug 9, 2003.

  1. What are the differences between HashMap and TreeMap? What is the
    application of each implementation?

    Thanks in advance!
     
    Ahmed Moustafa, Aug 9, 2003
    #1
    1. Advertising

  2. Ahmed Moustafa

    Adam Maass Guest

    "Christophe Vanfleteren" <3> wrote in message
    news:5ycZa.58282$-ops.be...
    > Ahmed Moustafa wrote:
    >
    > > What are the differences between HashMap and TreeMap? What is the
    > > application of each implementation?
    > >
    > > Thanks in advance!

    >
    > A TreeMap implements SortedMap, so when you iterate over the contents,
    > you'll get the content sorted by either their natural order, or by a
    > Comparator you definied when creating the TreeMap.
    >
    > With the regular HashMap, iterating over the content can result in any

    order
    > (you won't get them in eg. the order you inserted them into the Map).
    >
    >


    Insertion into a HashMap is, on average, much quicker than insertion into a
    TreeMap containing as many elements.

    If order is not important, use HashMap.

    -- Adam Maass
     
    Adam Maass, Aug 10, 2003
    #2
    1. Advertising

  3. Ahmed Moustafa

    Roedy Green Guest

    Roedy Green, Aug 10, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry

    TreeMap problem...

    Harry, Sep 22, 2003, in forum: Java
    Replies:
    3
    Views:
    498
    Harry
    Sep 23, 2003
  2. Wendy S
    Replies:
    4
    Views:
    14,271
    Jim McMaster
    Feb 19, 2004
  3. Miguel Angel
    Replies:
    9
    Views:
    14,384
    Christian Kaufhold
    Apr 15, 2004
  4. Vince Darley
    Replies:
    4
    Views:
    4,563
    emilchacko
    Mar 2, 2010
  5. Rakesh
    Replies:
    10
    Views:
    12,271
    Mike Schilling
    Apr 8, 2008
Loading...

Share This Page