• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashTables

 
Gary Guion
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
 
Gary Guion
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Gary Guion
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
sanjay kumaresan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic