Hello All,

I really hope that someone can provide some assistance.

I have read a XML file into my hashtable. Next I created a second hashtable. If a key is located in my first hashtable, I want that key along with its value to be inserted into the second hashtable.

For example the code below: if hash contains the key "info" put the key "info" along with its value into hash2. However when it it displayed I want to display the value, which is the description.

for(int i = 0; i < 7; i++)
       {
           if(hash.containsKey(hash.get(info)))
                 {
                    hash2.put(hash.t.car[i].getName(), 
                    hash.t.car[i].getDescrip());
                              
                   }   
       }

This is done so when I try to remove a key I can just test for the key "info" and remove the value, which is description.

if(hash2.containsKey(info) )
         {
            hash2.remove(info);
         }

The problem is that when I try to "put" items into the hashtable they simply will not go into the hashtable. What am I doing wrong?

Any assistance will be greatly appreciated.

Thanks

Recommended Answers

All 6 Replies

if(hash.containsKey(hash.get(info)))

This line makes no sense; you are getting the value that is associated with the key "info", and then you are testing whether that value is a key in the hash table?

How is this? I still have the same problem. It will not go into the hashtable.

for(int i = 0; i < 7; i++)
                        {
                          if(hash.containsKey(info))
                           {
                           hash2.put(hash.t.car[i].getName(), 
                           hash.t.car[i].getDescrip());
                                        
                           }
                        }

The problem has to be with how I am using the put method. When I test the put method with simple strings it works fine.

Well, I have made some progress. But it still will not "remove" the item from the hashtable.

this is how I used the put method:

hash2.put(hash.get(info), hash.getDescrip());

However when I use the remove method it will not remove the info from the hashtable.

Any suggestions?

Thank you,

can we see more code? for example, what types are all these things? how are they defined?

All are type Objects with the exception of "info", which is a String read from user input. Of course hash and hash2 represents the hash tables.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.