struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sandeep Takhar <sandeep_tak...@yahoo.com>
Subject RE: Urgent!!!Sorting Problem while loading from HashMap
Date Tue, 08 Jul 2003 12:41:40 GMT
Be careful about TreeMap though.

If you have equivalency in the comparator it will
remove one of the objects...

Read the javadocs carefully.

sandeep
--- Kris Schneider <kris@dotech.com> wrote:
> TreeMap:
> Red-Black tree based implementation of the SortedMap
> interface. This class
> guarantees that the map will be in ascending key
> order, sorted according to the
> natural order for the key's class (see Comparable),
> or by the comparator
> provided at creation time, depending on which
> constructor is used.
> 
> SequencedHashMap:
> A map of objects whose mapping entries are sequenced
> based on the order in which
> they were added.
> 
> TreeMap implements SortedMap, SequencedHashMap does
> not. You may also be
> interested in looking at LinkedHashMap which was
> added to Java in 1.4.
> 
> Quoting Andrew Hill
> <andrew.david.hill@gridnode.com>:
> 
> > 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:ParthasarathyK@PLANETASIA.COM]
> > 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:andrew.david.hill@gridnode.com]
> > > 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:ParthasarathyK@PLANETASIA.COM]
> > > 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
> 
> -- 
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message