Multidimensional hashmap or something alse array related.

I need something in Java that would allow me to set multidimentional arrays with the ability to set String values as both as keys  and as the value.  Also, I need to be able to check if the keys exists within one and two dimentions.  Something like.

myPlan[0][0] = "cell 1"
myPlan[0][1] = "cell 2"
myPlan[0][2] = "cell 3"
myPlan[1][0] = "cell 4"
myPlan[1][1] = "cell 5"
myPlan[1][2] = "cell 6"

than I need to be able to check if centerain keys exist for the first set/dimention, for example myPlan.containsKey(0), as well as for both dimentions myPlan.containsKey(0)(2).  I don't want to check for values it has to check if the keys exist, which at times may be Strings.

I'm not sure if HashMap is even the correct thing to use in this instance and I'm not familiar with Vectors to start figuring it out on my own.  

Thanks for your help and recommenations.
Who is Participating?
petmagdyConnect With a Mentor Commented:
Hi kasiencja,

u can still use a single Hastable object, but the key will be a Class u will define (Key2D) that implements equals() and hashCode() Methods, this will be the Key and the Value will  be the string:

public class Key2D {
 int xCordinate;
 int yCordinate;

 public boolean equals(object) {
   if(object instanceof Key2D) {
    // cast object to Key2D and compare x and y

 public int hashCode() {
    //Convert x, y to Strings and concatinate them with space badding based on maximum lenght and then return the hashCode of the result String
   return concatentaionResult.hashCode();

now u can search the Hashtable using hashtable variable.containsKey(instanceOfKey2D)

u can also use any Map based object instead of Hashtable like HashMap or TreeMap, etc.....
kasiencjaAuthor Commented:
Hmm, I just looked over the code again and it looks like I might be able to get away with the key values being set to int only.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.