• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hashtables and Maps

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm confused by how a hashtable works? Is it a spreadsheet style collection where you can store multiple columns of information under a key? Or is it limited to just one column per key?

Ie..

Key, data1, data2, data3

I need a collection which can store a series of data which is related

Thanks
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,

the bad news is,that in a Hashtable you can store one value per one key only.
If you for example put in a value under a same key which was already used, that former key-value-pair will be overwritten by the newly made input.

The good news is, that you do store Objects in Hashtables.
So for example, you coud put in this:


If you need to get back your many things, you just call:


(Don't forget, you always have to cast back your objects to their previous shape.)

An other very cool thing with Hashtables (and their related collection classes) is that you can store in them even whole other classes, interfaces etc. This can be very powerful.
 
It's weird that we cook bacon and bake cookies. Eat this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic