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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:10:24+00:00 2026-06-15T03:10:24+00:00

How can I get an array of elements in a ArrayList of HashMaps ?

  • 0

How can I get an array of elements in a ArrayList of HashMaps? I have an HashMap with url key on it. The value is a url address. Several HashMaps are stored in a ArrayList. What I want is an array with all url strings. I’m not happy with the solution I found because I think it could be extracted from ArrayList with some manipulation.

    // Hashmap for ListView        
    ArrayList<HashMap<String, String>> itemsList = new ArrayList<HashMap<String, String>>();

    // Creating JSON Parser instance
    JSONParser jParser = new JSONParser();
    jParser.execute(url); 

    try {
        JSONObject json = jParser.get();

        items = json.getJSONArray(TAG_ITEMS);
        //This is the solution that I want to optimize
        urls = new String[items.length()];

        // looping through All items
        for(int i = 0; i < items.length(); i++){
            JSONObject c = items.getJSONObject(i);

            // Storing each json item in variable
            String title = c.getString(TAG_TITLE);
            String description = c.getString(TAG_DESCRIPTION);
            String author = c.getString(TAG_AUTHOR);

            // Media is another JSONObject
            JSONObject m = c.getJSONObject(TAG_MEDIA);
            String url = m.getString(TAG_URL);

            // creating new HashMap
            HashMap<String, String> map = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            map.put(TAG_TITLE, title);
            map.put(TAG_DESCRIPTION, description);
            map.put(TAG_AUTHOR, author);
            map.put(TAG_URL, url);

            // Solution
            urls[i] = url;

            // adding HashList to ArrayList
            itemsList.add(map);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }
  • 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-15T03:10:26+00:00Added an answer on June 15, 2026 at 3:10 am

    From what I can deduce from your question, it sounds like you’re trying to do the following

    // Assuming previously declared and instantiated urls ArrayList with populated values in the nested HashMaps. 
    ArrayList<HashMap<String, String>> urls;
    // Create a new List using HashMap.values from urls.
    List<String> urlList = new ArrayList<String>(urls.get(index).values());
    

    urls.get(index).values() will return a Collection view of the values contained in the HashMap at the specified ArrayList index, which will be used to instantiate and populate a new ArrayList.

    If you want to obtain all of the values within each of the nested HashMaps or urls, you can do so in a similar manner, but you will need to iterate through the entire urls ArrayList

    for (HashMap<String, String> urlValues : urls) {
        urlList.addAll(urlValues.values());
    }
    

    P.S. Forgive my bad variable names!

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

Sidebar

Related Questions

how can i get elements uniquely from an array
How can I get the last key of an array?
Please tell me how can I get array of all Those DIV of specific
Is there a way I can get this array walk with my anonymous function
How can I get an array of values from an associative array ? Associate
How can I get the array data from a JSON sent back by my
how can i get [user_id] from this array? Array ( [2] => cbpaidSubscription Object
How can I get all the function arguments in javascript inside an array? function(a,
How can I get a list of unique values in an array? Do I
I wanted to know how can we get the index of the array if

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.