Didnt think to use a TreeMap - good idea!

When accessed via the Map interface the difference you perceive is one of
implementation efficiency - the SequencedHashMap uses a HashMap internally -
and it entries also have references that will preserve the list order, while
a TreeMap uses a tree internally which of course can be traversed in order.

According to the docs, the HashMap will give you a "fast O(1) search time"
for lookups while the TreeMap has "guaranteed log(n) time" - so I guess for
a huge collection the HashMap would be faster. That said I doubt your
requirements approach anything like the size needed for a noticable
difference in lookup time, and HashMaps are noted to be quite heavy when it
comes to memory use so Id say the TreeMap is a better choice. :-)

-----Original Message-----
From: O_Parthasarathy Kesavaraj [mailto:[EMAIL PROTECTED]
Sent: Tuesday, 8 July 2003 13:48
To: 'Struts Users Mailing List'
Subject: RE: Urgent!!!Sorting Problem while loading from HashMap


Thanks Navjot and Andrew..
Meanwhile i tried to convert it to TreeMap.It is working fine..But Andrew..
what is the difference between TreeMap and SequencedHashMap b'coz TreeMap
itself is giving me the list in order of how i have stored
Regds
Partha

> ----------
> From:         Andrew Hill[SMTP:[EMAIL PROTECTED]
> Reply To:     Struts Users Mailing List
> Sent:         Tuesday, July 08, 2003 10:45 AM
> To:   Struts Users Mailing List
> Subject:      RE: Urgent!!!Sorting Problem while loading from HashMap
>
> HashMaps will rearrange stuff internally and will NOT preserve the
> original
> order (see the j2se javadocs for details).
>
> There is a class in commons-collections (which should already be on your
> classpath as struts (1.1 anyway) uses this library) called
> SequencedHashMap - try using this instead as it preserves the order in
> which
> stuff was added to the hashmap and uses this order in its iterator.
>
> (This was introduced in commons-collections 2.0 so if your using an older
> version you may need to upgrade the jar with the latest.
>
> Heres the javadoc for it:
> http://jakarta.apache.org/commons/collections/api/org/apache/commons/colle
> ctions/SequencedHashMap.html
>
> -----Original Message-----
> From: O_Parthasarathy Kesavaraj [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, 8 July 2003 13:17
> To: 'Struts Users Mailing List'
> Subject: Urgent!!!Sorting Problem while loading from HashMap
>
>
> Hi
> I am loading a html:select box with property as the key in the HashMap( ID
> corresponding to the value which is displayed) and labelproperty as the
> value.When i am fetching from the database i am sorting by the value and
> then only loading in the HashMap.But when i see the select box the values
> are not sorted..which makes my form not so userfriendly...Kindly help to
> display sorted when i am loading from a HashMap...(When i load using an
> araylist it displays the values in the order i have stored and there is no
> sorting problem)
>
> Thanks in Advance
> Regds
> Partha
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to