• Post Reply Bookmark Topic Watch Topic
  • New Topic

Map inerface in a project  RSS feed

 
Krishna Tota
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

HashMap and HashTable are the classes provides the implementations for the Map interface.

And these stores Object references in the form of Key value pairs.

Please give some examples when we use these classes in a project.

And explain in brief.
Thanks,
Krishna.
 
sanjay kumar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I think this is a wrong place to look for tutorial/theory.

try the sun.com reference/tutorial very helpful and try your own examples.. will be more helpful.

Do come back here for any queries/doubts but don't expect theories..

anyways follow this link collections help
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37496
545
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like homework. What do you think the answer is?
 
K Sathya Narayanan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Both Hashtable and HashMap provides an unordered , unsorted map.

1. if you are not particular in which the elements need to be iterated , then you can use Hashtable or HashMap. but if you want to iterate in particular order and use a Map , then you can go for either LinkedHashMap or TreeMap. LinkedHashMap helps to iterate in the inserted order or access order(last accessed first). The TreeMap helps to iterate in the sorted order.

But Hashtable or HashMap or faster in adding/ removing the elements. But as the elements in TreeMap increases , time taken to add a element in the TreeMap increases. The Iteration of LinkedHashMap is little faster than HashMap.

so if you are not worried in the order in which elements need to be accessed , you can use Hashtable or HashMap.

2. The Hashtable can be used in multi threaded environment which requires that only one thread should access the data. As Hashtable methods are synchronized , it suits the need. If you don't want to allow null values , you can use Hashtable.

But if your project is based on a single threaded model , then you can use HashMap. HashMap also allows one null key and many null values. The methods of HashMap are not synchronized , so it executes faster and not suitable for multi-threaded environment

if require the data to be iterated in a random particular order and needs a Map then you can use HashMap or Hashtable.

Hashtable for multi-threaded application or web-based application and HashMap for Single Threaded Application or desktop application.

HTH
K Sathya Narayanan
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!