Java collection -Hashtable

Ads
 

Java collection -Hashtable

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.

Ads









Related Tutorials/Questions & Answers:
Collection in java
Collection in java  What are the meaning of the letters E,T,K and V that come in the collection concept
Java collection
Java collection  What is relation between map and set
Advertisements
java collection
java collection  how do I use a treeset to print unique words
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
Filter collection in Java 8
Filter collection in Java 8  Hi, I have following collection..., Example of Filter collection in Java 8 You can use the following code in Java 8... the data not containing "Java". Thanks   Hi, We have huge collection
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
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
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
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
How to convert Collection to Array in Java?
How to convert Collection to Array in Java?  Hello, I have a collection object in data with data in it. How to convert Collection to Array in Java... to Array in Java. Here is the code for converting Collection to Array: String
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 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 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
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 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
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
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
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
What is the purpose of garbage collection in Java, and when is it used?
What is the purpose of garbage collection in Java, and when is it used?  Hi, What is the purpose of garbage collection in Java, and when is it used... of Garbage collection in Java. so Please visit the link and clear your doubts
What is the best way to filter a Java Collection?
What is the best way to filter a Java Collection?  Hi, I have... to filter a Java Collection? Thanks   Hi, In Java 8 you can use... is using Java 8. Thanks   Hi, We have huge collection of Java util package
Collection
Collection  What is the exact difference between lagacy classes and collection classes? and Enumeration is possible on Collection classes
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
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
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
Collection framework
Collection framework  what are the real life examples of using Collection in java
Collection of Large Number of Java Interview Questions!
Interview Questions - Large Number of Java Interview Questions Here you... usually asked in the Job Interviews.     Huge collection.... The Core Java Interview Questions
Jaca Collection
Jaca Collection  does Java collection allow incompatible types to be stored in single collection
Java Collection : NavigableSet Example
Java Collection : NavigableSet Example In this tutorial we are describing NavigableSet of collection Framework NavigableSet : NavigableSet interface... collection; import java.util.Iterator; import java.util.NavigableSet; import

Ads