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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:26:09+00:00 2026-05-21T15:26:09+00:00

I was told to change everything to HashMap() instead of ArrayList() and for the

  • 0

I was told to change everything to HashMap() instead of ArrayList() and for the most part everything worked perfect. However, I am having a problem getting this one method to work properly.

my HashMap() looks like

private HashMap critMap = new HashMap();

I have Room class and Creature class Room can have Creatures in it. The Creatures need to be able to react to certain commands which I already have methods for and should work as long as this method is right. I’m not certain to what is wrong.

This is the method with ArrayList()

public void critReactRoomStateChange2(String command, PC pc, String name) {
    Creature temp = null;
    for (int i = 0; i < critArr.size(); i++) {
        if (!(getCreatures().get(i) instanceof PC) && !(getCreatures().get(i).getName().equals(name))) {
            temp = getCreatures().get(i);
            if (temp != null) {
                getCreatures().get(i).reactStateChange(command, pc);
                temp.checkNewRoom();
                if (!temp.equals(getCreatures().get(i))) {
                    i--;
                }
            }
        }
    }
}

THIS IS THE METHOD AFTER I TIRED TO IMPLEMENT HashMap()

public void critReactRoomStateChange(String command, PC pc, String name) {
    Creature temp = null;
    if (!(getCreatures().get(name) instanceof PC)) {
        temp = getCreatures().get(name);
        if (temp != null) {
            getCreatures().get(name).reactStateChange(command, pc);
            temp.checkNewRoom();
        }
    }
}

the getCreatures().get(name) is taking the String name that is passed to it as a key of the hashMap to find the actual object it is referring to. As stated above my hashMap is thus the creatures name is the String(key) and the value Creature(contains other information other than name) is the value. When I call getCreature().get(name) I am looking for the Key String name and I want it to return the object Creature. If it cannot find it in the hashMap it should return null unless I’m mistaken.

I might just be missing something really simple. Any help would be greatly appreciated. If more code is needed I’d gladly edit this and put it in.
Thanks

Edit: Creature class is a is abstract and PC, Animal, NPC all extend it. Just so your not wondering what the random PC and NPC and Animals are doing. lol

Edit2: No error besides that I’m not getting the reactions. It does nothing so critReactRoomStateChange is not working now. The Creatures are not getting passed along so the other methods can act on it.

So the 2nd box of code isn’t working properly. It does nothing essentially.

  • 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-21T15:26:09+00:00Added an answer on May 21, 2026 at 3:26 pm

    I see that when you were using an ArrayList you applied the method getCreatures().get(i). It could be that you didn’t change the getCreatures() method after you switched to HashMap since after the change you dont need to loop and get(i).

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

Sidebar

Related Questions

No related questions found

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.