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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:47:15+00:00 2026-06-03T01:47:15+00:00

Am trying to gives more than one value to a key in a map.

  • 0

Am trying to gives more than one value to a key in a map. I wanted something of this kind to work..
mapp.put(“key1″,”value1”)
mapp.put(“key1″,”value2”).
The first value “value1” is getting over-ridden with “value2”. How to retain both the values? Should I go for any other thing than maps for this to happen?

  • 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-03T01:47:17+00:00Added an answer on June 3, 2026 at 1:47 am

    You can use un map with list. Something like that:

    Map<String, List<String>> map = new HashMap<String, List<String>>();
    

    For put a key1 with the first value:

    if (!map.containsKey("key1")) {
        map.put("key1", new LinkedList<String>());
    }
    map.get("key1").add("value1");
    

    For add the second value to key1

    map.get("key1").add("value2");
    

    You can have all this in one method

    public void add(String key, String value) {
        if (!map.containsKey(key)) {
            map.put(key, new LinkedList<String>());
        }
        map.put(key, value);
    }
    

    If you want the values for the key1, you obtain a List

    List<String> values = map.get("key1");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create more than one table in the database but the
I'm trying to write a query that gives me a percentage (i.e. something like
when I'm trying to compile my c program it gives me this error warning:
I'm trying to set this up where the user gives username and password in-app,
I'm trying this code to access a property but it gives me an error:
I am trying to download more than 1m pages (URLs ending by a sequence
I'm trying to work out if this is possible, let me give an example.
I'm trying to build words in arrays by their key value in a dictionary.
Trying to decode an invalid encoded utf-8 html page gives different results in python,
I am trying to initialize NSDictionary but it gives me following error: Program received

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.