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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:16:42+00:00 2026-05-28T08:16:42+00:00

I am using hashmap, but it is not working correctly. I have a class

  • 0

I am using hashmap, but it is not working correctly. I have a class Computing.java, where I have method for adding into hashmap:

addIntoMap(String key, String value){

   m_parameters_values.put(key, value);
   }

and method for get from hashmap:

public void getValueByKey(String key){
        System.out.println("GET "+m_parameters_values.get(key));
    }

I am calling theese methods from Main class, but I am not able to be able to get keys, I am still getting null. Do you know why?

Content of class computing (constructors omitted):

public void Parse (String args[]) throws Exception{
        Parse(args,true);
    }

    public void Parse(String[] args, boolean throwErrorIfParamenterNotDefined) throws CmdLineException
    {


        int i = 0;

        while (i < args.length)
        {
            // The current string is a parameter name
            String key = args[i].substring(1, args[i].length() - 1).toLowerCase();
            String value = "";
            i++;
            if (i < args.length)
            {
                if (args[i].length() > 0 && args[i] == "-")
                {
                    // The next string is a new parameter, do not nothing
                } else
                {
                    // The next string is a value, read the value and move forward
                    value = args[i];
                    i++;
                }
            }

            if (!m_parameters.containsKey(key))
            {
                if (throwErrorIfParamenterNotDefined)
                {

                    //throw new CmdLineException("Parameter is not allowed.");

                }
                //continue;
            }
            System.out.println("Key: "+key+" value: "+value);
            m_parameters_values.put(key, value);
            //System.out.println("GET "+m_parameters_values.get("provider"));
            }

        // Check that required parameters are present in the command line. 

        for (String key : m_parameters.keySet())
        {
            if (m_parameters.get(key).required() && !m_parameters.get(key).exists())
                throw new CmdLineException("Required parameter is not found.");
        }


    }

    public void getValueByKey(String key){
        System.out.println("GET "+m_parameters_values.get(key));
    }

Content of main class:

public static void main(String[] args) {

    Computing comp = new Computing("Computing");    

        cmdLine.Parse(args);
        cmdLine.getValueByKey("convert");
  • 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-28T08:16:42+00:00Added an answer on May 28, 2026 at 8:16 am

    print value used in put method.

    Acc. to javadoc:

    A return value of null does not necessarily indicate that the map contains no mapping for the key; it’s also possible that the map explicitly maps the key to null.

    To be sure, use containsKey method to verify if key really exists.

    use following code in getValueByKey; and see if it prints anything:

    if (m_parameters.containsKey(key))
    {
        System.out.println("GET "+m_parameters_values.get(key));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In java while using the HashMap, they are using the Iterator class. But I
I was thinking of using a Double as the key to a HashMap but
I'm building a thesaurus using a HashMap <String,ArrayList<String>> to hold words and their synonyms
I have a HashMap that I'm using in Processing and I'd like to increment
I am having problems using the update method of scala.collection.immutable.HashMap.I don't see the reason
Using the STL C++ hash_map... class MyKeyObject { std::string str1; std::string str2; bool operator==(...)
I have to parse a XML structure in JAVA using the SAX parser. The
I'm having trouble using my own class as a key for a HashMap public
I am using this code in order to do this, but it is not
I've been making some objects using the pimpl idiom, but I'm not sure whether

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.