java programming

How do we add a class to a Collection object using hashtable(using a string as key)?
sraveendAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sironoCommented:
or, just to write is out:

public void addToHashTable()
{
    HashTable myHashTable = new HashTable();
    String key = "this is the key";
    Object value = new Object();

    myHashTable.put(key, value);
}

that's it :)
0
rk_radhakrishnaCommented:
import java.util.*;
class Hashme {

        public static void main (String arg[]) {

                Hashtable h = new Hashtable ();

 

                //put new elements in a hash table

                h.put("one", new Integer(32510) );

                h.put("Two", new Integer(52510) );

                h.put("Three", new Integer(12013) );

                System.out.println("Hash table contains: " + h);

 

                // Check if the hash table is empty

                System.out.println("Hash table is empty? " + h.isEmpty());

 

                // getting value from a hash table against a key

                System.out.println("Two contains Value: " + h.get("Two"));

 

                //finding a value

      System.out.println("The value 32510 exists? " + h.contains (new Integer(32510)));

 

                //finding a key
      System.out.println("The key three exists? " + h.containsKey ("Three"));

 
      //removing an object against a key
            System.out.println("Removing three: " + h.remove ("Three"));

 
      //finding the latest status of hash table
System.out.println("Hash table now contains: " + h);

      System.out.println("Size is: " + h.size());

        }


}

find some info. about Hashtables:
http://www.javaworld.com/javaqa/2002-06/01-qa-0621-hashtable.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

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.