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

  • Home
  • SEARCH
  • 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 7951505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:34:56+00:00 2026-06-04T02:34:56+00:00

I need to have a resultset converted into a Map of Maps. The reason

  • 0

I need to have a resultset converted into a Map of Maps.
The reason why I’m not using a List of Maps is because I don’t want to iterate through the entire List to get a specific row.

The problem I am facing now is that the HashMap’s entries aren’t ordered anymore if the index is greater than 16.

Now I tried the following for a simple test:

    public static void main(String[] args) {

    Map<Integer, String> map = new HashMap<Integer, String>();

    //creating 20 rows from 1 to 20
    for (int i = 1; i <= 20; i++){
        map.put(i, "ROW "+i);   
    }


    //returning all the rows the map contains. Look at position 16.
    for(int key : map.keySet()){
        System.out.println(key);    
    }
}

And the output is the following (look at position 16 to 20. They are totally unordered):

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 16 19 18 20

I would really appreciate it, if someone can explain why that happens.

And by the way:

i cant use something like this:

for (int i = 0; i < map.size; i++){
    map.get(i) //...and so on

}

because I don’t know if the index exists. It may be that that the index from 200 to 800 doesnt exist. So it would be better only to iterate through exisiting entries of the map.

  • 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-06-04T02:34:58+00:00Added an answer on June 4, 2026 at 2:34 am

    A HashMap is not ordered or sorted. If you need an insertion ordered Mapuse java.util.LinkedHashMap.
    If you need a Mapsorted by the key, use a SortedMapsuch as java.util.TreeMap

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

Sidebar

Related Questions

I have an xml resultset which has to be converted using XSL for display
I have the need to convert a hex string into an integer using C#.
I have need to pack four signed bytes into 32-bit integral type. this is
Hi I have a json string converted unsing the JSON framework into a dictionary
I have an array of Floats that need to be converted to a byte
I have a problem in sql where I need to generate a packing list
I am using SSIS (VS 2008) and I want to take a populated resultset
I basically have 7 select statements that I need to have the results output
I have need to return multiple results from a subquery and have been unable
i need to connect to another server we manage and have it's results (in

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.