• 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

Hashtable vs. Array

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is beter Hashtable or Array to use for programing?
 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It really depends what you need. In array you will put the entry in specified index. Arrays also has to have definite size, you cannot increase the size of the array on the fly.
Hashtables are using keys and values. You can increase the size of the hashtable. You have a lot more flexibility with accessing entries of hashtable by key or by entry itself, you can remove the entry (which you cannot do in array). Check java API for more references.
 
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hashtable has the qualities of a hashtable, such as constant time lookup and insertion. It is excellant for storing key->object mappings.
Arrays cannot be looked up based on a key. And looking up for a specific object requires traversing the array.
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Array is of course better because Hashtable is an outdated (replaced by HashMap), slow (uselessly synchronized with only linear performance) relic, whereas Arrays are an integral part of the Java language itself with constant time performance and bounds checking that supports static type checking (unlike the Collections).
 
reply
    Bookmark Topic Watch Topic
  • New Topic