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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:45:52+00:00 2026-05-28T05:45:52+00:00

I have an Arraylist of HashMap . Each HashMap element contains two columns: column

  • 0

I have an Arraylist of HashMap. Each HashMap element contains two columns: column name and corresponding value. This HashMap will be added into a ListView with 3 TextView.

I populate the ArrayList as follows, and then assign that to an adapter in order to display it:

ArrayList<HashMap<String, String>> list1 = new ArrayList<HashMap<String, String>>();
HashMap<String, String> addList1;
for (int i = 0; i < count; i++) {

addList1 = new HashMap<String, String>();
addList1.put(COLUMN1, symbol[i]);
addList1.put(COLUMN2, current[i]);
addList1.put(COLUMN3, change[i]);

list1.add(addList1);

RecentAdapter adapter1 = new RecentAdapter(CompanyView.this,
                    CompanyView.this, list1);
listrecent.setAdapter(adapter1);
        }

.

Now on listItemClick, the fetched data is of the different form at different time.

For eg. My list contains following data:

ABC  123  1
PQR  456  4
XYZ  789  7

i.e. When I log the fetched string after clicking 1st list item, I get one of the several outputs:

{1=ABC ,2=123 ,3=1}

{First=ABC ,Second=123 ,Third=1}

{1=123 ,0=ABC ,2=1}

and even
{27=123 ,28=1 ,26=ABC}

Initially I used:

int pos1 = item.indexOf("1=");
int pos2 = item.indexOf("2=");
int pos3 = item.indexOf("3=");

String symbol = item.substring(pos1 + 2,pos1 - 2).trim();
String current = item.substring(pos2 + 2, pos3 - 2).trim();
String change = item.substring(pos3 + 2, item.length() - 1).trim();

Then for the 4th case, I have to use:

int pos1 = item.indexOf("26=");
int pos2 = item.indexOf("27=");
int pos3 = item.indexOf("28=");

String symbol = item.substring(pos1 + 3, item.length() - 1).trim();
String current = item.substring(pos2 + 3, pos3 - 3).trim();
String change = item.substring(pos3 + 3, pos1 - 3).trim();

So that I get ABC in symbol and so on.

But, by this approach, application loses it’s reliability completely.

I also tried

while (myVeryOwnIterator.hasNext()) {

key = (String) myVeryOwnIterator.next();
value[ind] = (String) addList1.get(key);
                }

But it’s not giving proper value. Instead it returns random symbol for eg. ABC or PQR or XYZ.

Am I doing anything wrong?

Thanks in advance!

  • 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-28T05:45:53+00:00Added an answer on May 28, 2026 at 5:45 am

    The HashMap’s put function does not insert value in specific order. So the best way is to put the keyset of the HashMap in a ArrayList and use the ArrayList index in retrieving the value

    ArrayList<HashMap<String, String>> list1 = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> addList1;
    ArrayList<String> listKeySet;
    for (int i = 0; i < count; i++) {
    
    addList1 = new HashMap<String, String>();
    addList1.put(COLUMN1, symbol[i]);
    addList1.put(COLUMN2, current[i]);
    addList1.put(COLUMN3, change[i]);
    
    listKeySet.add(COLUMN1);
    listKeySet.add(COLUMN2);
    listKeySet.add(COLUMN3);
    
    list1.add(addList1);
    
    RecentAdapter adapter1 = new RecentAdapter(CompanyView.this,
                    CompanyView.this, list1);
    listrecent.setAdapter(adapter1);
    }
    

    And when retrieving use

    addList1.get(listKeySet.get(position));
    

    Here, the arraylist listKeySet is just used to preserve the order in which the HashMap keys are inserted. When you put data in HashMap insert the key into the ArrayList.

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

Sidebar

Related Questions

I have an ArrayList of HashMap . Each HashMap contains many key-value-pairs. I want
I have an ArrayList . Each element is a HashMap lookup for my values.
I have an arraylist that contains items called Room. Each Room has a roomtype
I have two arraylists A1, A2. Each element of A1 would be the key
I have a problem with comparing two arraylist, my first arraylist looks like this:
i have two arrays (actually one, but i created two for each columns). I
e.g. I have a need where my ArrayList should contain hashmap at each index,
I have an ArrayList<HashMap<String, String>> . I'd like to quickly extract from this a
I currently have a custom listview where each item on the list contains two
I have a List of HashMap such as below ArrayList l = new ArrayList

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.