Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collection  RSS feed

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I wanted to store set of information like employee number, employee name, and employee address what class in the collection framework do i have to use so that when i search on the employee number, it would give me the employee name and address, could somebody pls help me with some code.
Thanks
Chris
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

have a employee class to store all employee related values in it.
Since u plan a search on the employee number,
Use java.util.Hashtable and use the employee number as the key there with employee class instance as the value.
So u need to wrap the key in Integer class though (java problem :-(, removed in C# though!).
class Employee{
String name;
String address;
int empNo;
}
Hashtable h = new Hashtable();
h.put(new Integer(empNo),
new Employee(//supply name/address to constrctor));
h.put(new Integer(empNo),
new Employee(//supply name/address to constrctor));
//repeat.
Now h.get(empNo) w'd get u the details corresponding to that employee.
karthik.
 
Chris Chua
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That one would really work thanks very much Karthik Gutu
Chris
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!