• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Map inerface in a project

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sounds like homework. What do you think the answer is?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic