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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:31:42+00:00 2026-06-05T13:31:42+00:00

In this Java project I’m looking at, I keep seeing code with HashMap, like

  • 0

In this Java project I’m looking at, I keep seeing code with HashMap, like so

 /** imageID --> image map */
    Map<String,ImageIcon> imgs = new HashMap<String,ImageIcon>();

Then later in the class:

// images 
loadImages();
actualImage = imgs.get(this.DEFAULT_IMAGE_ID);
JLabel label = new JLabel(actualImage);

What is the purpose of this code? I am foggy on the whole concept here.

  • 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-05T13:31:43+00:00Added an answer on June 5, 2026 at 1:31 pm

    Both provide key-value access to data. The Hashtable is one of the original collection classes in Java. HashMap is part of the new Collections Framework, added with Java 2, v1.2.

    The key difference between the two is that access to the Hashtable is synchronized on the table while access to the HashMap isn’t. You can add it, but it isn’t there by default.

    Another difference is that iterator in the HashMap is fail-safe while the enumerator for the Hashtable isn’t. If you change the map while iterating, you’ll know.

    And, a third difference is that HashMap permits null values in it, while Hashtable doesn’t.

    Answer to your edited question:

    /** imageID --> image map */
    //imageID - String. imgs is a map of imageID and ImageIcon. imageID is key. ImageIcon is value.
        Map<String,ImageIcon> imgs = new HashMap<String,ImageIcon>();
    

    Then later in the class:

    //SEE INLINE COMMENTS
    // images 
    //No definition provided. May be putting values into the imgs map.
    loadImages();
    //this.DEFAULT_IMAGE_ID is some imageID. imgs.get gets the value for that imageID, which
    //is ImageIcon for that imageID. That is stored in actualImage variable.
    actualImage = imgs.get(this.DEFAULT_IMAGE_ID);
    //Creating a new JLabel with actualImage.
    JLabel label = new JLabel(actualImage);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to display image that locates outside the my java project,
Now I have a FTP service. The config like this: http://wso2.org/project/esb/java/3.0.1/docs/samples/transport_samples.html#Sample254 . It works
I've just found in my java project this code snippet: List<IssueType> selectedIssueTypes = new
We have a class LogManager in our Java project which looks like this: public
My Java project structure in Eclipse looks like this: myproject src/main/java com.mypackage.mysubpackage1 com.mypackage.mysubpackage2 com.mypackage.mysubpackage3
This is more or less my first java project. I can't get my while
I am using Netbeans IDE for a java project. In this project i need
I am utilizing the javax.scripting with Rhino in this project. I have a Java
This Java code converts a timestamp into a Long value: Long.toString(new Timestamp(System.currentTimeMillis()).getTime(), 36) As
Given this Java code: class Account { private Integer number = 0; public synchronized

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.