The HashMap class does not do any sorting, since it implements the Map interface not the SortedMap interface. However (from the Javadocs):
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time." Consider using an additional second Collection, but use some List (e.g. ArrayLisy) which stores the keys in the sequence in which they was added. Then this list can be iterated over in the order that the key-value pairs where added to the HashMap and the Key can be used to retrieve the Value from the original map quickly (since it is a hash-map). > -----Original Message----- > From: Lakshmeenarayana G G [SMTP:[EMAIL PROTECTED]] > Sent: 22 November 2002 06:51 > To: [EMAIL PROTECTED] > Subject: Hashtable / HashMap Problem. > > Hi, > > I am using Hashtable or HashMap to keep Key-Value pair of elements. > But When I add them, The Hashtable or HashMap gets sorted depending on the > keys. > I want to retain the order in which I have added the key-value pair. > Is there anyway to do it with Hashtable or HashMap ? > > Or Can I use any other Collection type which will have the mapping of > key-value which is not sorted other than two dimensional Array. > > Thanks for the time. > Lakshmeenarayana G G > CLI Division - SysArris Software > Bangalore - India > Tel. No. +91-80-665 4965, 665 5052, 664 2690 Xtn-240 > Fax No. +91-80-665 0374, 655 4285 > http://www.sysarris.com/ > > ========================================================================== > = > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff > JSP-INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST > DIGEST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com -- It is the strict policy of Truworths that its e-mail facility and all e-mail communications emanating therefrom, should be utilised for business purposes only and should conform to high professional and business standards. Truworths has stipulated certain regulations in terms whereof strict guidelines relating to the use and content of e-mail communications are laid down. The use of the Truworths e-mail facility is not permitted for the distribution of chain letters or offensive mail of any nature whatsoever. Truworths hereby distances itself from and accepts no liability in respect of the unauthorised use of its e-mail facility or the sending of e-mail communications for other than strictly business purposes. Truworths furthermore disclaims liability for any unauthorised instruction for which permission was not granted. Truworths Limited accepts no liability for any consequences arising from or as a result of reliance on this message unless it is in respect of bona fide Truworths business for which proper authorisation has been granted. Any recipient of an unacceptable communication, a chain letter or offensive material of any nature is requested to notify the Truworths e-mail administrator ([EMAIL PROTECTED]) immediately in order that appropriate action can be taken against the individual concerned. =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com