• Post Reply Bookmark Topic Watch Topic
  • New Topic

Use Vector or Hashtable?  RSS feed

 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!