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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:13:23+00:00 2026-05-28T22:13:23+00:00

I have a HashMap<String,String> and there is a static method which returns this map

  • 0

I have a HashMap<String,String> and there is a static method which returns this map to an Activity.

Method looks like this:

public static HashMap<String, String> getAll() {    
    HashMap<String, String> map = new HashMap<String,String>();

    map.put("ab", "value1");
    map.put("bc", "value2");
    map.put("de", "value3");

    return map;
}

I want to use that map with a spinner. So activity looks like this:

List list = new ArrayList<String>();
HashMap<String, String> map = Constants.getAll();

for (String key : map.keySet()) {
    list.add(Constants.getAll().get(key).toString());
}

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

spinTest = (Spinner)findViewById(R.id.spinTest);

spinTest.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
        urlDebug.setText(list.get(arg2).toString());
    }

    public void onNothingSelected(AdapterView<?> arg0) {

    }
});

spinTest.setAdapter(adapter);

When I tried to run my application, no problem at all. But when I clicked on spinner, items not ordered as I added on getAll() method. I mean, order has to be ab – bc -de but it’s ordered randomly.

What’s not true?

  • 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-28T22:13:24+00:00Added an answer on May 28, 2026 at 10:13 pm

    in hashmap, insertion order is not maintained, so item inserted last may accessed first. If you want to maintain order of insertion, use linkedhashmap instead.

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

Sidebar

Related Questions

If I have a HashMap that looks like this: HashMap<String, MyObject> where the String
Is there some way of initializing a Java HashMap like this?: Map<String,String> test =
I have a hashmap like this public HashMap <String,People> valueHashMap = new Hashmap(); Here
I have a map of constants, like this: private static Map<String, Character> _typesMap =
I have a final non-static member: private final HashMap<String,String> myMap; I would like to
I have this HashMap<String, ArrayList<Item>> , is there a way to count the total
I have HashMap like: static HashMap<String,ArrayList<Media>> mediaListWithCategory=new HashMap<String,ArrayList<Media>>(); I have value like: January: -Sunday
I have a variable of type Hashmap <String,Integer >. In this, the Integer value
I have the following code: Map<String, ObjectType> objectMap = new HashMap<String, ObjectType>(); for (ObjectType
If I have the value foo , and a HashMap<String> ftw for which ftw.containsValue(foo)

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.