Alternative to PHP's associative arrays in JAVA?

What you are describing is an associative array also called a table, dictionary, or map In Java, you want the Map interface, and probably the HashMap class as the implementation Map myMap = new HashMap(); myMap. Put("cat", 123); Integer value = myMap. Get("cat"); //123.

What you are describing is an associative array, also called a table, dictionary, or map. In Java, you want the Map interface, and probably the HashMap class as the implementation. Map myMap = new HashMap(); myMap.

Put("cat", 123); Integer value = myMap. Get("cat"); //123.

Ah. Thank you. Actually I was using a HashMap, but I wrote some part of my code wrong so that the map wasn't behaving like a HashMap.

Damn these tiny mistakes... – some guy Oct 1 at 0:48 @someguy What was it behaving like?! – Dave Newton Oct 1 at 1:20.

You want to use a Map, most likely a HashMap.

The data structure you are after is Map. I believe its an abstract class so you'll have to use one of its concrete subclasses like HashMap.

You would use one of the Map implementations such as HashMap to do that.

As many people said, a Map is what you are looking for. If that was your choice, do not forget to reimplement hashcode() and equals(). Take a look because is a must: ibm.com/developerworks/java/library/j-jt....

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions