1

I am inserting some values in hashtable. But its not keeping the order as i inserted.

 for (int i = 0; i < SignatureKey.size(); i++) {

               m.put(SignatureKey.elementAt(i), SignatureValue.elementAt(i));
    }

please suggest something.

Rince Thomas
  • 4,158
  • 5
  • 25
  • 44

1 Answers1

4

By its nature a hash table should be an unordered collection. If you want to preserve the ordering of your elements, use a different data structure.

Alan
  • 3,307
  • 1
  • 19
  • 22
  • can you please explain which data structure, I can use to preserve the order. I need this for native blackberry development. – user2218773 Apr 03 '13 at 12:19
  • but how can i put keypair values in a vector. – user2218773 Apr 04 '13 at 04:24
  • 1
    One way would be to make a keypair class, and have a vector of those. [Take a look at this topic](http://stackoverflow.com/questions/521171/a-java-collection-of-value-pairs-tuples). – Alan Apr 04 '13 at 09:10