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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:47:21+00:00 2026-05-29T14:47:21+00:00

As part of an ongoing class project, we were asked to implement Maps for

  • 0

As part of an ongoing class project, we were asked to implement Maps for better object linking.

In short, we currently have four arraylists which hold objects

// Array Lists used for sorting.
private static ArrayList<Party> partyList = new ArrayList<Party>();
private static ArrayList<Creature> creatureList = new ArrayList<Creature>();
private static ArrayList<Treasure> treasureList = new ArrayList<Treasure>();
private static ArrayList<Artifact> artifactList = new ArrayList<Artifact>();

Each class has their own fields (ie, Party has “index”,”name”, Creature has “index”, “name”, “age”, height”, etc…but they all have a unique index)

This week we are to implement hashmaps, where the key of an object, is its index.

so, as an exmaple:

creatureMap.put(creature.index, creature)
...

Our program also allows searching. So i understand that now when we search by an index, we just search the appropriate hashmap for the index we want, and work with the object that is its value.

However, our program also allows the user to search by name, height, weight, etc. So, how are hashmaps being used efficiently here if it only helps when searching by index? What happens if i want to search a creature by name? I would have to loop through every value in the hashmap, look at its ‘name’ field..which is exactly what i am doing with the arraylist.

Our professor said this when someone asked a similar question:

The idea is that in the first project, the simple approach was to
insert all items into array lists and when one needed to link a
creature to a party, or an item to a creature, one would have to
search the ArrayList linearly until the index of the item was found.
This is O(n) operation if the ArrayList is not sorted, and an O(log n)
operation if the list is sorted, but the sorting is typically O(n*n)
or O(n log n) depending on the sorting operation used.

This week, I am asking you to implement an O(1) searching system based
on a map data structure. Thus, we should use the index of a item as
its key to generate the links. This is used once during processing of
the input file.

Thus, I am not sure i am understanding the concept of Maps / key-value pairs correctly.

  • 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-29T14:47:23+00:00Added an answer on May 29, 2026 at 2:47 pm

    Your understanding is correct: if your key is an index, you can only use the map to efficiently lookup by index. If you wanted to search by name, then you would have to key on the name.

    I’m not too sure on what your professor meant by this:

    Thus, we should use the index of a item as its key to generate the links.

    (I think he refers to linking objects by index, as in “link a creature to a party” – maybe he did not refer to the use of hashmaps for searching)

    On a side note, it’s good practice to declare variables based on interfaces rather than concrete types. In your example, you should define your list fields as List instead of ArrayList:

    private static List<Party> partyList = new ArrayList<Party>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web part for managing comments related to ongoing promotions. The web
Part of a new product I have been assigned to work on involves server-side
Part of my application maps resources stored in a number of locations onto web
As part of an ongoing process of trying to upgrade my C++ skills, I
This is a two part question; firstly, does anyone out there have some insight
I have been having an ongoing fight with this email setup. The code below
This has been an ongoing struggle for me for the last four days. I
I have a customer using the Access 97 runtime to support part of their
We currently have a quite complex business application that contains a huge lot of
I currently have a status bar notification that goes off when an mp3 is

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.