Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


erastus
hashtable
1 Answer(s)      5 years and 11 months ago
Posted in : Java Beginners



Advertisement
View Answers

September 11, 2008 at 6:17 PM


Hi ,


A hash-table is a data-structure that consists of an array of linked lists.

The beauty of this arrangement is that you can have the speed of array-access, along with the convenience of inserting objects into linked lists. What's more, inserting and searching through a hash-table is very, very fast.


import java.util.*;
import java.io.*;
import java.util.Hashtable;


public class HashTableTest {

public static void main(String args[]){
System.out.println("welcome to Roseindia");
Hashtable hash = new Hashtable();

hash.put("amar","amar");
hash.put("vinod", "vinod");
hash.put(hash,"all");
hash.put(hash, hash);

try{
System.out.println("Display list : " + hash);
}

catch(Exception e){
System.out.println("error in table:" + e.getMessage());
}
}
}

--------------------------------

import java.util.*;

public class StackExample {
public static void vectorShow ( Vector v ) {
System.out.println ( "printing vector contents" ) ;
for ( int i = 0, length = v.size ( ) ; i < length; i++ )
System.out.println ( v.get ( i ) ) ;
}
public static void main ( String [ ] args ) {
Stack<String> stack = new Stack<String>( ) ;
//Treat as a Stack
stack.push ("welcome") ;
System.out.println(stack.pop ( ) ) ;
//Treat as a vector
stack.add ( "1" ) ;
stack.add ( "2" ) ;
stack.add ( "3" ) ;
System.out.println ( stack.get ( 2 ) ) ;
System.out.println ( stack.contains ( "1" ) ) ;
stack.insertElementAt ( "5", 1 ) ;
stack.removeElementAt ( 2 ) ;
vectorShow(stack) ;
}
}

------------------------------------
import java.util.*;

public class QueueList {
public static void main(String[] args) {
Queue<String> queue = new LinkedList<String>();
queue.offer("amar");
queue.offer("vinod");
queue.offer("suman");
queue.offer("deepak");

System.out.println("Size of list: " + queue.size());
System.out.println("Queue head using peek : " + queue.peek());
System.out.println("Queue head using element: " + queue.element());
Object data;
while ((data = queue.poll()) != null) {
System.out.println(data);
}
}
}

------------------------------

Visit for more information.

http://www.roseindia.net/java/

Thanks.

Amardeep


Related Tutorials/Questions & Answers:
Java hashtable
Java hashtable   What is hash-collision in Hashtable and how it is handled in Java
Differences between HashMap and Hashtable?
Differences between HashMap and Hashtable?  Differences between HashMap and Hashtable
Advertisements
Java hashmap, hashtable
Java hashmap, hashtable  When are you using hashmap and hashtable
hashtable java swing
hashtable java swing  i m getting this warning code is here Hashtable nu=new Hashtable(); Hashtable ns=new Hashtable(); nu.put(new... mber of the raw type Hashtable plz help me
Java collection -Hashtable
Java collection -Hashtable   What is Hashtable in java collection?   Java collection -Hashtable;- The hashtable is used to store value... { public static void main(String [] args){ Map map = new Hashtable
The Hashtable Class
The Hashtable Class In this section, you will learn about Hashtable and its implementation with the help of example. Hashtable is integrated... it also stores key/value pair in Hashtable. But the difference is Hashtable
hashtable - Java Beginners
hashtable  pls what is a hashtable in java and how can we use it to compine queue and stacks. thnks in advance.  Hi , A hash-table... to Roseindia"); Hashtable hash = new Hashtable(); hash.put("amar","amar"); hash.put
Doubts regarding Hashtable - Java Beginners
Doubts regarding Hashtable  Hi, I am new to hashtable.Is it possible to create a hashtable like this? java.util.Hashtable hashtable=new...(12,13,10,1)); since we get the key of hashtable from the database. When I tried
Java Collection : Hashtable
Java Collection : Hashtable In this tutorial, we are going to discuss one of concept (Hashtable ) of Collection framework. Hashtable  : Hashtable.... When you increase the entries in the Hashtable, the product of the load
Java Hashtable Iterator
be traversed by the Iterator. Java Hashtable Iterator Example import java.util.*; public class hashtable { public static void main(String[] args) { Hashtable hastab = new Hashtable(); hastab.put("a", "andrews
J2ME HashTable Example
J2ME HashTable Example       To use the HashTable, java.util.Hashtable package must be imported into the application. Generally HashTable are used to map the keys to values
Hashtable java prog - Java Interview Questions
Hashtable java prog  Create a hashtable with some student hall ticket numbers and their results. when we type a hallticket number,it shud display the results? please provide the detail java code for this? thanks in advance
Hashtable java prog - Java Interview Questions
Hashtable java prog  Create a Hashtable with some students hall ticket numbers and their results. when you type a hall tickets number,it shud display... bal; Hashtable table = new Hashtable(); table.put( new Integer(1111),"Selected
Create JTree using an Object
object that works with Hashtable.  Program Description:  This program... the init() method that uses a Hashtable object to store data .This object is added...;void init(){   Hashtable hash = new Hashtable
Break a Line for text layout
is used. The class Hashtable maps keys to values. A string is defined...;new Hashtable();      private static 
Media MIDlet Example
created an 'item' object for Hashtable and put all 'wav' file in this table...;items = new Hashtable();   itemsInfo = new Hashtable();   items.put("Kyo Aage-Piche Dolte 
Collections in Java
, LinkedList, Stack and Hashtable. Collections is a group of objects. Objects can
HashMap in Java
HashMap class is used to implement Map interface. The value of HashMap is stored using get() and put(). HashMap provides key-value access to data. HashMap is almost equal to HashTable, the only difference is that HashMap allows null
difference
difference  difference between hashtable and hashtree
spring - Spring
spring  what is the use of HashTable concept in spring
Collections - Java Interview Questions
Collections  By default, Hashtable is unordered. Then, how can you retrieve Hashtable elements in the same order as they are put inside
java - Java Beginners
Java hashtable null values  How to get if there is null value in the Java hashtable? and is it possible to accept both null and values
java
java  What is the super class of Hashtable?  The Dictionary class is the abstract parent Hashtable
Java Collection
Java Collection  What are Vector, Hashtable, LinkedList and Enumeration
Java collection
Java collection  What are differences between Enumeration, ArrayList, Hashtable and Collections
Collections Framework
Collections Framework  Sir, We know that both HashMap & Hashtable.... But there is some difference between this two class that are 1)Hashtable is synchronized but HashMap not. 2)Hashtable doesn't contain null but HashMap can. My question
Java collection
Java collection  What are differences between Enumeration, ArrayList, Hashtable and Collections and Collection
hashcode() and equals() - Java Interview Questions
hashcode() and equals()  can you give one hashtable prog using equals() and hashcode()?PLease..thanks in advance
Map
Map  Hi how can we retrieve key - value pair from hashtable and hashmap? how can we retrieve arraylist element? Thanks Kalins Naik   Please visit the following links: HashTable Example ArrayList Example HashMAp
Java - Java Interview Questions
Java  By default, Hashtable is unordered. Then, how can you retrieve Hashtable elements in the same order as they are put inside?  Hi friend, Please visit the following link to solve your problem. http
Java RMI and Threading
while running this. 2. When we compare string values with hashtable values it is not properl working sample code is Hashtable hash_modeChange = new Hashtable(); Hashtable hash_statusChange = new Hashtable(); if ((hash
collection
, Hashtable and Collections and Collection?   Enumeration : It is series... or values of a hashtable. We can not remove elements from Enumeration. ArrayList.... It permits all elements, including null. It is not thread safe. Hashtable
hashcode() and equals() - Java Beginners
hashcode() and equals()  plesae give an example of hashtable using... (String args[]){ java.util.Hashtable hashtable = new java.util.Hashtable... of hashtable is: "+hashtable.size()); } } class Entity{ int id; Entity(int id
java - Java Interview Questions
to be remember: *)Hashtable is part of legasy class we can use enumerator interface of this hashtable class. *)Hashtable will not allow null key nor values
Equals() and Hashcode() - Java Interview Questions
these methods while using Hashtable? Please Explain it detaily along with an java... of hashtable using equals() and hashcode
java - Java Beginners
). The membership is kept in a hashtable for ease of searching for details about.... The hashtable is accessed by surname not by code name. Applicants for the Club... is accepted as a member, given a code name and added to the hashtable. The membership
tinny ennis - Java Beginners
). The membership is kept in a hashtable for ease of searching for details about... are kept. The hashtable is accessed by surname not by code name. Applicants... is accepted as a member, given a code name and added to the hashtable
java program(Hash Table) - Java Beginners
, Code to solve the problem : import java.util.*; public class HashTable { public static void main(String args[]) { Hashtable table = new Hashtable(); //Put value into the table table.put("Delhi
java - Java Beginners
HashTable ? how can we enter the Keys and Values in HashTable ? would u give...... Hashtable is a concrete implementation of Dictionary from java2... to HashMap, but is synchronized hashtable stores key/ value pairs
java
: Enumeration BitSet Vector Stack Dictionary Hashtable Properties These classes
ParseQueryString
ParseQueryString   What is use of parseQueryString ?   It parses a query string and builds a Hashtable of key-value pairs, where the values are arrays of strings. The query string should have the form of a string
Equals() and Hashcode() - Java Beginners
these methods while using Hashtable? Please Explain it detaily along with an java.... Thanks   can you give one hashtable prog using equals() and hashcode
MultiThreading
replace HashMap with HashTable. Its nicely suited for multi-threaded apps
Building a Binary Tree using std::map, std:set
as sorted arrays/lists/hashtable
JSP,DB
JSP,DB  How to store the resultset of a query in a hashtable n... in a hashtable n retriving bt dont know hw to do it?can u help me??.. My query...(); ResultSet rs=st.executeQuery("select * from data where id=1"); Hashtable
Data Structures in Java
Hashtable Properties After the release of Collections in Java 2 release
Hashmap
Hashmap  public class HashTable { public static void main(String args[]){ HashMap hm=new HashMap(); hm.put(new Integer(2), "Two"); hm.put...*; public class HashTable { public static void main(String args[]){ HashMap hm
equals and hashcode
{ public static void main (String args[]){ java.util.Hashtable hashtable = new...)); System.out.println("Size of hashtable is: "+hashtable.size()); } } class Entity
Example to show Hash table exception in java
;hashtable = new Hashtable();   hashtable.put("Girish"...;Elements in the Hashtable");   Enumeration e ... java.util.NoSuchElementException: Hashtable Enumerator
Advertisements
 

 

 

DMCA.com