Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3439566
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:19:33+00:00 2026-05-18T08:19:33+00:00

I inserted some data into a Java Hashtable. If I read the data from

  • 0

I inserted some data into a Java Hashtable. If I read the data from the Hashtable it doesn’t come back in the same order that I inserted it in. How do I get the ordered data from the Hashtable?

I use the following code to get the values from the hashtable:

// Get a set of the entries
Set set = hsUpdateValues.entrySet();
// Get an iterator
Iterator i = set.iterator();
// Display elements
while (i.hasNext()) {
    Map.Entry me = (Map.Entry) i.next();            
    System.out.print(
        "Key : " + me.getKey()
        + ", Value: " + me.getValue()
    );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:19:33+00:00Added an answer on May 18, 2026 at 8:19 am

    If you want an order-preserving map, you should use LinkedHashMap:

    Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if m.put(k, v) is invoked when m.containsKey(k) would return true immediately prior to the invocation.)

    This implementation spares its clients from the unspecified, generally chaotic ordering provided by HashMap (and Hashtable), without incurring the increased cost associated with TreeMap.

    Note that this is usually compared with HashMap rather than Hashtable – I don’t know of an order-preserving equivalent to Hashtable; the latter isn’t usually used these days anyway (just as ArrayList is usually used in preference to Vector).

    I’ve assumed you want insertion order rather than key-sorted order. If you want the latter, use TreeMap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some way to get a value from the last inserted row? I
What's the best way to get the last inserted id using sqlite from Java?
I'm inserting some data into a database from a form. I'm using addslashes to
I have an insert statement that pulls some data into a few table variables
I inserted some values into a table. There is a column whose value is
I have a basic HTML form that gets inserted into a server side div
I have inserted some data in table using encryption (encrypted by creating my own
I am loading some data into a temp table. I then use a cursor
I want to insert some data into a table (id PK autoincrement, val) with
I'm trying to insert some data into a local MySQL database by using MySQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.