• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ordering Hashtable elements

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am adding elemets in Hashtabl.I want the elements in the order I add the elements.but Hashtable is

public static void main(String[] args)
{
Hashtable h =new Hashtable();
h.put(" login",new Object());
h.put("Dent",new Object());
h.put(" creditcard",new Object());



Enumeration e= h.keys();
for (; e.hasMoreElements(); ) {
Object oVal= (Object)e.nextElement();
System.out.println("key in HT is "+(String)oVal );
}
}


output is

key in HT is Dent

key in HT is creditcard

key in HT is login


Can soem one help what should I do to guarentee the order I added.Is there any thing else I can use.I want key vaule pairs.I can not use ArrayLsit

Thanks in advance
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hashtable doesn't maintain the order in which the elements are stored. If you want to preserve the order, you can use java.util.LinkedHashMap.
 
Saritha Reddy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
reply
    Bookmark Topic Watch Topic
  • New Topic