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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:39:11+00:00 2026-05-26T18:39:11+00:00

I want to get the key of a HashMap using the value. hashmap =

  • 0

I want to get the key of a HashMap using the value.

hashmap = new HashMap<String, Object>();

haspmap.put("one", 100);
haspmap.put("two", 200);

Which means i want a function that will take the value 100 and will return the string one.

It seems that there are a lot of questions here asking the same thing but they don’t work for me.

Maybe because i am new with java.

How to do it?

  • 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-26T18:39:12+00:00Added an answer on May 26, 2026 at 6:39 pm

    The put method in HashMap is defined like this:

    Object  put(Object key, Object value) 
    

    key is the first parameter, so in your put, “one” is the key. You can’t easily look up by value in a HashMap, if you really want to do that, it would be a linear search done by calling entrySet(), like this:

    for (Map.Entry<Object, Object> e : hashmap.entrySet()) {
        Object key = e.getKey();
        Object value = e.getValue();
    }
    

    However, that’s O(n) and kind of defeats the purpose of using a HashMap unless you only need to do it rarely. If you really want to be able to look up by key or value frequently, core Java doesn’t have anything for you, but something like BiMap from the Google Collections is what you want.

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

Sidebar

Related Questions

I want to get the MD5 Hash of a string value in SQL Server
I want to get started doing some game development using Microsoft's XNA. Part of
I want to get the base 10 logarithm of a Fixnum using Ruby, but
I have set up a HashMap like so: Map<String, ArrayList<String>> theAccused = new HashMap<String,
I want to get all the values associated with a key in Map. For
I'm trying to put some key values in HashMap and then trying to sort
I have a HashMap<String,String> (called p2p ) and I want to make a loop
I want to search the hashmap after a key and if the key is
I have a Collection as Vector<HashMap<String, String>> Actually I am using this as list
I have a HashMap having key as my own object and key as 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.