File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes HashTables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashTables" Watch "HashTables" New topic
Author

HashTables

Gary Guion
Greenhorn

Joined: Jun 21, 2001
Posts: 23
Could someone give me an idea (in english) what a hashtable is and what I would use the HashTable class for? I have been programming in java for about a year, but I need to begin to understand more than "Hello World".
Thanks,
Gary
Greg Mathaus
Greenhorn

Joined: Jun 29, 2001
Posts: 4
Visit http://java.sun.com/products/jdk/1.1/docs/api/java.util.Hashtable.html
Gary Guion
Greenhorn

Joined: Jun 21, 2001
Posts: 23
I know where the API's are. I just wanted an example in laymans terms. Thanks, but do you have any examples etc.
Gary
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4749
    
    7

Then perhaps you've haven't found this link to the Collections trail in the Java Tutorial yet:
http://java.sun.com/docs/books/tutorial/collections/interfaces/map.html

Junilu - [How to Ask Questions] [How to Answer Questions]
Gary Guion
Greenhorn

Joined: Jun 21, 2001
Posts: 23
Thanks
sanjay kumaresan
Greenhorn

Joined: Jun 29, 2001
Posts: 8
Gothrough the code. Definitely you will get what is hashtable and how to use it.
/*Hashtable is used to store and retrieve objects*/
import java.util.*;
class htable
{
public static void main(String args[])
{
Hashtable h=new Hashtable(); //Default constructor
int i=0;
String s[]={"Sun","MicroSoft","Bell"}; //object initialize
//storing the object in the hashtable.
h.put(s[0],"java");
h.put(s[1],"c#");
h.put(s[2],"c");

//getting the objects one by one
while(i<h.size())>
{
System.out.println(h.get(s[i]));
i++;
}
h.clear(); //clear the hashtable
} //end of main
}

The while loop condition is
i less than h.size()
If you want more information about hashtable mail me. I will give the details.
Email id: sanjaykumaresan@rediffmail.com
M.Sanjay

[This message has been edited by sanjay kumaresan (edited July 01, 2001).]
[This message has been edited by sanjay kumaresan (edited July 01, 2001).]
[This message has been edited by sanjay kumaresan (edited July 01, 2001).]
[This message has been edited by sanjay kumaresan (edited July 01, 2001).]
[This message has been edited by sanjay kumaresan (edited July 01, 2001).]
shalina gokarna
Greenhorn

Joined: Jul 01, 2001
Posts: 10
Respected Sir,
A HashTable is a class in the java.util package.If I am working on a Chat Application in Java,then I can make use of an Hashtable.
An Array has a fixed number of cells so if I want to add some new friends in my Chat list,then I can't do it by using an Array.But I can do the same by using a HashTable because I can expand as well as shrink the size of an HashTable.I can store the list of friends in it and can retrieve it accordingly.
That's exactly the use of an Hashtable.An HashTable is similar to a multi-dimensional array.It makes use of certain keys internally which points to the specific record in the HashTable.
There are certain classes like an Hashtable,StringTokenizer etc.in the java.util package that are used in Projects which are made in Advanced Java.
That is the point where exactly you can make use of these classes which are present in the java.util package.
regards,
Shalina.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HashTables