[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Hash Table

Posted on 2000-01-14
2
Medium Priority
?
175 Views
Last Modified: 2010-04-16
Hallo,
I wanna clear somethings in Hashtable.
How can i use Hashtable as Database?
I've created one hashtable,But I not able to append some new records to that
Hash table.Is it possible?
Could u please clear other features about Hashtable&Vector?
0
Comment
Question by:purushoth
2 Comments
 
LVL 7

Accepted Solution

by:
Ravindra76 earned 150 total points
ID: 2355364

Hi ,


why are u not able to append???


Use Hashtable's put() methods which will take key value pair.

Use Hashtable get() method to get data.

See your jdkhome\src\java\util\Hashtable.java for api's.

Hashtable as database:


1.Create a class which represent your table.employee as empid,name,salary


Eg: public class Employee {
   public int empId;
   public Stirng name;
   public double salary;
}

Assme that empId is primary key.

Create a object of Employee.

Employee emp = new Employee();
emp.empId = 1;
emp.name="somename",
emp.salary=12000;

Hashtable records = new Hashtable();
records.put(empId,emp);
// Key and value pair

// In some where you can get data as
int empId = 1;
Employee emp = (Employee) records.get(empId);//giving key and getting value

System.out.println("Emp salaey:"+emp.salary);

Best of luck.



0
 

Author Comment

by:purushoth
ID: 2361598
Thanx a lot for your guidance.
My doubt was cleared.

Regards,
Purushoth.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 4 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question