• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write a class use Hashtable to add, update, delete an Object....?  RSS feed

 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have an User.java class, include the fields:
String name;
int age;

i would like to save this class into a Hashtable to add, update, delete the User object.
I want to write a class that's "Manager.java" to excute this:


Please suggest me to write add(), update(), delete() methods complete this class (Manager class), and how to test it?
Thanks you very much, and sorry for my stupid quesion.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand why you need a Hashtable to store a User object. Hash tables are used to store multiple objects, each under a unique key, not for storing a single object. Can you clarify what you're trying to do?
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, thanks for your reply,
I would like to build an applycation to manage the room conference. So my application include 3 part:
+ Information about Users (Use Hashtable): id (Integer), name (String), age (String), home number(String)
+ Information about Room (use Linked list): id, roomID, projector, location (location of the room)
+ Information about reservation (Use vector to store): id, roomID, time, amount, purpose.
At the present, I want to store info of users into Hashtable and add, update, delete, and transmit to a vector to add into a TableModel to display in JTable.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK. Do you have a specific question about the task you set out to do? Without knowing what "the room conference" is, or where you're stuck implementing it, it's hard to advise you on how to proceed.
[ March 27, 2008: Message edited by: Ulf Dittmer ]
 
Tran Tuan Hung
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, thanks,
My problem is i am using an Hashtable to read data from Database, but to display data in JTable, i must use vector, so for now, i would like
to write a method to convert Hashtable to Vector.
Thanks and best regards,
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashtable and Vector are not equivalent data structures, so you'll need to think about how you want to do this. Should all entries of the Hashtables become Vector elements? If so, what about the Hashtable keys - do you still need those?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!