Home Answers Viewqa Java-Beginners Java collection -Hashtable

 
 


Naulej kumar
Java collection -Hashtable
1 Answer(s)      11 months ago
Posted in : Java Beginners

What is Hashtable in java collection?

View Answers

June 21, 2012 at 1:51 PM


Java collection -Hashtable;-

The hashtable is used to store value in the form of map key with value.

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;


public class HashTableExample {
 public static void main(String [] args){
     Map map = new Hashtable();
      map.put("A", "Apple");
      map.put("B", "Orange");
      map.put("C", "Grapes");
      map.put("E", "Pine");
      map.put("D", "Mango");

      Iterator iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry mapEntry = (Map.Entry) iterator.next();
            System.out.println("The key is:" + mapEntry.getKey()
                    +  ", value is :" + mapEntry.getValue());
    }
  }
}

Output:

The key is:A, value is :Apple
The key is:E, value is :Pine
The key is:D, value is :Mango
The key is:C, value is :Grapes
The key is:B, value is :Orange

Description:- The above example demonstrates you the Map interface. Since Map is an interface, you need to instantiate a concrete implementation of the interface in order to use it. Here Map is implemented by its subclass Hashtable. Using the put method, we have added elements to key and value pair. Now to display the key and values, we have called getKey() and getValue() methods that are defined by Map.Entry.









Related Pages:
collection
collection  As we know array holds the similar kind of elements, then in collection how toArray() method will convert the collection having different objects as elements to an array in java
Collection
Collection  i need a collections examples   Please visit the following links: http://www.roseindia.net/javacodeexamples/index.shtml http://www.devmanuals.com/tutorials/java/collections
Java Collection
Java Collection  What is the Collection interface
Collection in java
Collection in java  What are the meaning of the letters E,T,K and V that come in the collection concept
Collection framework
Collection framework  what are the real life examples of using Collection in java
Jaca Collection
Jaca Collection  does Java collection allow incompatible types to be stored in single collection
garbage collection
garbage collection  how to use garbage collection in program using core java
Garbage collection
Garbage collection  why garbage collection? How it works?   Garbage collection is one of the most important features of Java. The purpose... collection is also called automatic memory management. In Java, it is good idea
Java garbage collection
Java garbage collection  What is Garbage Collection and how to call it explicitly
garbage collection in java
.style1 { color: #FFFFFF; } Garbage Collection in Java In java...;  C:\unique>java GarbageCollector Garbage Collection... are destroyed for later reallocation of their memory. In java this is done automatically
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Collection Framework - Java Beginners
Collection Framework  Pls explain the disadvantages of using collection framework as it was written in this forum ? It must cast to correct type. ? Cannot do compile time checking. I couldnot get in detail as to what
collection - Framework
://www.roseindia.net/java
Java Collection API - Java Tutorials
Java Collection API Collection was added to Java with J2SE 1.2 release. Collection framework is provided in 'java.util.package'. All collections... of the collection interfaces. Also, they are reusable data structures. Algorithms
Java collection-LinkedList
Java collection-LinkedList  How to use java collection-linked list ?   Example: import java.util.Iterator; import java.util.LinkedList; import java.util.List; public class LinkedListExample{ public static void
garbage collection - Java Beginners
of memory.It identifies the objects that are no longer used by a program. A Java object is subject to garbage collection when it becomes unreachable to the program..."algorithms.Instead of "destructor" in c++ , java supports garbage collector
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
Java collection Queue Example
Java collection Queue Example  How can we use Queue in java collection?   import java.util.LinkedList; import java.util.Queue; public... LinkedList(); queue.add("Java"); queue.add("DotNet
Java collection LinkedHashSet
Java collection LinkedHashSet  How can we use LinkedHashSet in java collection?   import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; public class LinkedHashSetExample{ public static
Java Collection-TreeSet
Java Collection-TreeSet  What is TreeSet in Java Collection?   Example: import java.util.Iterator; import java.util.TreeSet; public class TreeSetExample{ public static void main(String [] args
Java collection Stack example
Java collection Stack example  How to use Stack class in java collection?   The Stack class uses the First In Last Out(FILO) mechanism... :- -1 Description:- The above example demonstrates you the Stack class in java
Collection Interface
Java NotesCollection Interface The Collection interface is the parent... for identifiers in the table below: Collection coll; boolean b; Object obj; int i; Iterator it; ReturnsMethodAction Adding objects to a collection b = 
Collection Interface
Java NotesCollection Interface The Collection interface is the parent... for identifiers in the table below: Collection coll; boolean b; Object obj; int i; Iterator it; ReturnsMethodAction Adding objects to a collection b = 
Java collection HashSet
Java collection HashSet  How can we use HashSet in java program?   The hashSet class is used to create a collection and store it in a hash table. Each collection refer to a unique value. import java.util.Collections
Java collection Vector
Java collection Vector  How can we use the vector class in java program?   The vector class is similar to the ArrayList class except that the vector class is synchronized. import java.util.Iterator; import
java collection - Development process
java collection - creating and comparing lists using Java  How to compare two list in java? and i have to create two more list from old two list. Comparing and Creating new list in Java Java Example code for creating
java collection - Java Beginners
java collection  want a java program using collections for an algorithm the algorithm is give below algorithm has some transactions T1=ABCE T2=CDE T3=DE T4=CDEG T5=BG T6=AE T7=BCG T8=C T9=A now compare T9
Collection framework tutorial
framework in Java. I want many examples of Java collection framework. Tell me the best tutorial website for learning Java Collection framework. Thanks   Hi, Following urls are best for learning Java Collection framework: Collections
Java HashSet Collection problem
Java HashSet Collection problem  Here's how the HashSet works. It maintains an array of buckets. When an object is inserted, it finds the appropriate bucket corresponding to the objects HashCode. Then it calls the equals method
Java collection HashSet and TreeSet
Java collection HashSet and TreeSet   How can we used HashSet and TreeSet in the both Example?   import java.util.HashSet; import java.util.Set; import java.util.TreeSet; public class SetsExample{ public static
Java garbage collection
Java garbage collection  Can an unreachable object become reachable again
What is garbage collection? - Java Beginners
. How garbage collection works in java? Thanks   Garbage Collection in Java In Java when program executes the JVM creates the object... in Java. Check the garbage collection code at http://www.roseindia.net/answers
Java garbage collection
Java garbage collection  How many times may an object's finalize() method be invoked by the garbage collector
Java garbage collection
Java garbage collection  Can an object be garbage collected while it is still reachable
Array to Collection
Array to Collection       In this example we are converting values of an array into collection. List  interface is a member of the Java Collection Framework
Java Collection iterator with example
The Java Collection Iterator is present at the highest level interface in the Collection framework. Iterator interface has methods for traversing.... Example of Java Collection Iterator import java.util.ArrayList; import
Collection frame work - Java Beginners
Collection frame work  How to a sort a list of objects ordered by an attribute of the object
Collection
Collection  What is the exact difference between lagacy classes and collection classes? and Enumeration is possible on Collection classes
Collection to Array
; interface is a member of the Java Collection Framework and extends Collection... Collection to Array      ...; a collection into a array. In this example we creating an object of ArrayList, adding
Java Garbage Collection
Java Garbage Collection       The Java language is the most widely used programming language to rely on garbage collection. The name "garbage collection" implies
Iterate java collection
Collection is the top level interface of the Collection framework. Iterator interface has methods for traversing over the elements of the collection. But Collection doesn't has iterator() method. So create object
collection frame - Java Interview Questions
collection frame   starting from jdk1.0 to jdk 1.5,what are the feature s added in each version of collection frame up to jdk1.5 .  Hi friend, (1)Generics:Provides compile-time (static) type safety
java core collection - Java Interview Questions
java core collection  why program in collection package throw two warnings(notes
Collection
Collection  actually why do we need collections? means we can also store group of objects in relational data base and dbms also provides all the operatoins insert,delete,update,sort,search etc. then why collection
Which java collection to use in scenario below and Why?
Which java collection to use in scenario below and Why?  I want to store thousands of record in a collection and later I want to search. For best and optimized results, which collection will I prefer
Garbage collection process in java - Java Beginners
Garbage collection process in java  Name the process used for Garbage collection in Java? Thanks   Garbage collection process In Java the Garbage collection process is known as Garbage Collector. The Garbage
Collection Framework - Java Interview Questions
Collection Framework   While inserting an object which sould be prefered- ArrayList or LinkedList and why?  Inserting an object with ArrayListArrayListExample.javaimport java.util.*;import java.io.*;public class
asynchronous and synchronous collection
asynchronous and synchronous collection  which are all interfaces or classes are synchronous and asynchronous in java? please send it in table or picture form
core java collection package - Java Interview Questions
core java collection package  why collection package doesnot handle..., Java includes wrapper classes which convert the primitive data types into real Java Objects. There is no class in Java called int but there is a class called

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.