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 6704755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:19:30+00:00 2026-05-26T07:19:30+00:00

I’m having a weird problem with HashMap in Android. I’m putting values into the

  • 0

I’m having a weird problem with HashMap in Android. I’m putting values into the hashmap which is of the form

HashMap <String,String> sample = new HashMap<String,String>();

However let’s say I’m putting the following values in the following order:

sample.put("ifi1", "video1");
sample.put("ifi2", "video2");
sample.put("ifi3", "video3");
sample.put("ifi4", "video4");
sample.put("ifi5", "video5");
sample.put("ifi6", "video6");
sample.put("ifi7", "video7");
sample.put("ifi8", "video8");
sample.put("ifi9", "video9");

This is just a simple example that is similar to what i have. I only have a bigger list in my actual code. However when I now try to print only the values, I get an unordered list as follows:

VIDEOS: video1
VIDEOS: video3
VIDEOS: video2
VIDEOS: video5
VIDEOS: video4
VIDEOS: video7
VIDEOS: video6
VIDEOS: video9
VIDEOS: video8

where in fact I’m expecting it to produces the following list:

VIDEOS: video1
VIDEOS: video2
VIDEOS: video3
VIDEOS: video4
VIDEOS: video5
VIDEOS: video6
VIDEOS: video7
VIDEOS: video8
VIDEOS: video9

Why is this, any idea?

  • 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-26T07:19:31+00:00Added an answer on May 26, 2026 at 7:19 am

    That’s right. The HashMap implementation of Map does not guarantee any order during iteration.

    If you want ordering based on insertion…

    …have a look at LinkedHashMap:

    Map<String, String> sample = new LinkedHashMap<String, String>();
    
    sample.put("ifi1", "video1");
    sample.put("ifi2", "video2");
    sample.put("ifi3", "video3");
    sample.put("ifi4", "video4");
    sample.put("ifi5", "video5");
    sample.put("ifi6", "video6");
    sample.put("ifi7", "video7");
    sample.put("ifi8", "video8");
    sample.put("ifi9", "video9");
    
    for (String video : sample.values())
        System.out.println(video);
    
    // Prints
    video1
    video2
    video3
    video4
    video5
    video6
    video7
    video8
    video9
    

    If you want ordering based on the keys…

    Use a NavigableMap or SortedMap implementation such as a TreeMap.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.