• 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

Use Vector or Hashtable?

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I'm currently working on a system in which I use a Vector to store information extracted from a database. The vector is populated by using 1 or 2 buttons (Rent or Sale). I also have a JTable which displays the values stored in the vector.
The problem I am having is being able to distinguish between a "Sale" or "Rent". When the user selects the Rent or Sale button, the data is populated in the JTable. After they are done populating the JTable, there is a "Done" button which will the insert purchase and rental data into a database.
How am I able to distinguish between a Rental or a Sale? I was thinking to use a Hashtable in which I store the Vector and a boolean value. Then I thought it would be better to use a Vector of Vectors...
I am stuck at this point, as I am unsure how to go about retrieving the values of the Rental/Sale as well as the boolean to tell the system whether it's a rental or a sale.
I hope I am explaining this clearly... Any help is very much appreciated.

Thanks,
Frank
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm assuming you meant that you are trying to decide between an ArrayList and HashMap! I use a HashMap to represent a row in a table. The key is column name and the value is the column value. I add each row ( HashMap ) to an ArrayList which represents a table. Unfortunately the class is at work and I'm at home, so I can't post the code. Something similar was posted by Peter in the JDBC forum, so I'll try to dig it up. You could add another column to each HashMap for specifying rent/buy choice.
Anyways, you should stick to ArrayLists and HashMaps instead of Vector and Hashtable as they are outdated and not as flexible.
Jamie
[ April 12, 2003: Message edited by: Jamie Robertson ]
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry it wasn't in the JDBC forum, but in this one. Anyways have a look at Peter's code snippet here
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic