I have some data and I have added them to Hashtable in some orders what I want to do now is to get the data in the same order that I have entered
What is the data type that I can use?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming your key is a String you could add some ordering to it and have a getter method for the sorted data. See example below:
static int order; Hashtable map = new Hashtable(); void put (String key, Object value) { map.put(order + key, value); order++; } Enumeration getSorted() { Enumeration keys = map.keys(); Vector sortedKeys = new Vector(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); insertionSort(key, sortedKeys); } Vector sortedData = new Vector(); keys = sortedKeys.elements(); while (keys.hasMoreElements()) { String key = (String) keys.nextElement(); sortedData.addElement(map.get(key)); } return sortedData.elements(); }You can find insertionSort algorithms at http://en.wikipedia.org/wiki/Insertion_sort