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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:52:24+00:00 2026-05-30T06:52:24+00:00

I have a problem on arraylist and hashmap As according to my requirement, I

  • 0

I have a problem on arraylist and hashmap

As according to my requirement, I am storing the data into HashMap and after that I have created a List as List>.

        HashMap<String,String> hashmap;
        static List<HashMap<String,String>> hashmap_string;

And while retrieving the value from database and putting it on HashMap and ArrayList like:

                    contract_number=c.getString(c1);
                    Log.i("c1.getString,contract_number", contract_number);
                    String service_level=c.getString(c2);
                    hashmap=new HashMap<String, String>();
                    hashmap.put(contract_number, service_level);
                    hashmap_string.add(hashmap);

And now I want to retrieve the value as String,String

And when I am applying the code as:

                for(int i=0;i<hashmap_string.size();i++)
                {
                    Log.i("arraylist", ""+hashmap_string.get(i));
                }

I am getting a single string value in the formet as

               {Contract,ServiveValue}

but I want to split this into 2 string values…Also these values are redundant and if am using hashMap then it will not showing me the redundant value.

Please help me on this..

  • 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-30T06:52:25+00:00Added an answer on May 30, 2026 at 6:52 am

    HashMap (and Maps in general) are used for multiple one-to-one mappings of keys and values. Are you sure you need that? Looking at your code it appears you’re using the map as a “Pair” class. I would skip the list, and put everything in the same map, and then iterate over the pairs in the map:

    // using tree map to have entries sorted on the key, 
    // rather than the key's hash value.
    Map<String, String> data = new TreeMap<String, String>();
    data.put("c1", "s1");
    data.put("c2", "s2");
    
    for (Map.Entry<String, String> entry : data.entrySet()) {
        String contract = entry.getKey();
        String level = entry.getValue();
        Log.i("data", contract + " : " + level");
    }
    

    would output (assuming TreeSet):

    c1 : s1
    c2 : s2
    

    Alternatively, create e.g. a ContractServiceLevel class that holds two strings (the contract number and the service level), and put instances of that class in your list.

    EDIT:

    public final class ContractServiceLevel {
        public final String number;
        public final String serviceLevel;
    
        public ContractServiceLevel(String c, String s) {
            number = c;
            serviceLevel = s;
        }
    }
    
    List<ContractServiceLevel> contracts = new ArrayList<ContractServiceLevel>();
    contracts.add(new ContractServiceLevel("c1", "s1.1"));
    contracts.add(new ContractServiceLevel("c1", "s1.2"));
    contracts.add(new ContractServiceLevel("c2", "s2.1"));
    
    for (ContractServiceLevel contract : contracts) {
        Log.i("data", contract.number + ":" + contract.servicveLevel);
    }
    

    would output:

    c1 : s1.1
    c1 : s1.2
    c2 : s2.1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String,
I have a HashMap<String,String> and there is a static method which returns this map
Hello i have problem with my sms aplication. import java.util.ArrayList; import java.util.List; import android.app.Activity;
Hello i have a problem with this aplication. import java.util.ArrayList; import java.util.List; import android.app.Activity;
I need to use a HashMap of the form <String, ArrayList<String>> that is going
I am getting this strange output in HashMap . I have two ArrayList<String> one
I have problem in some JavaScript that I am writing where the Switch statement
I have problem when I try insert some data to Informix TEXT column via
I have problem with fancybox. I want to write a function that will run
I have a List containing HashMaps . Each HashMap in the list might have

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.