Is there an associative array type data structure in Java?

9

Well, I'm trying to name an Array of Strings in Java, but I wanted it to be, for example:

String[] symbols;

And that could be stated like this:

symbols["name"] = "Tiago";

I know that Array does not exist like this, but in some other way, how?

    
asked by anonymous 13.01.2015 / 22:10

1 answer

8

You can use the HashMap class to do this.

Example:

Map<String, Integer> vehicles = new HashMap<>();
vehicles.put("BMW", 5);
vehicles.put("Mercedes", 3);
vehicles.put("Audi", 4);
vehicles.put("Ford", 10);

See more about interface Map , and class HashMap on:

HashMap

Map

    
13.01.2015 / 22:16