0

I have tried using the Hashmap data structure to create an associative array in processing with objects as values and, of course, strings as keys.

http://processing.org/reference/HashMap.html

However, I couldn't get the values of my hash map to be objects of a class I made.

Here is what I tried:

class Person {

    public String firstName, lastName;

    Person(String f, String l) {
        this.firstName = f;
        this.lastName = l;
    }

}

HashMap<Person> persons;
persons = new HashMap();

Processing returns a bizarre error:

Cannot find anything named "persons"
4
  • Did you cast them to those objects? Where is your sniplet? Would be nice to see. Commented Mar 28, 2012 at 22:18
  • What's your base language? C#, Java or what? Can you put your code here so it will make it easy to understand problem. Commented Mar 28, 2012 at 22:20
  • I'm using the language of processing, which is based off of Java. I will be able to get a code snippet up asap. Commented Mar 28, 2012 at 22:22
  • try HashMap<Person> persons = new HashMap()<Person>; and then access by persons.get("index here"); Commented Mar 28, 2012 at 22:28

1 Answer 1

1

You can use a generic HashMap:

Map<String, Object> map = new HashMap<String, Object>();

// Save data:
map.put("associativeIndex", new Object());

// Access data:
map.get("associativeIndex");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.