Hi trupti ,
here i m giving two samples.Hope they will help u to some extent.
i m not able to make user id as a key to the hash table.
i think it will accept string type only.
i have to check it again.
if any queries let me know.
my mail id is :
[email protected] samples:
import java.io.*;
class userDetails
{
String user_name;
int user_id;
String user_birth;
String user_pwd;
userDetails()
{
user_name = new String();
user_birth = new String();
user_pwd = new String();
}
// copy constructor
userDetails(userDetails copy)
{
user_name = copy.user_name;
user_id = copy.user_id;
user_birth = copy.user_birth;
user_pwd = copy.user_pwd;
}
public String toString() {
return "user name = "+user_name+";user id = "+user_id+";user birth = "+user_birth+";user pwd = "+user_pwd;
}
void setuser_name(String n)
{
user_name=n;
}
void setuser_id(int i)
{
user_id=i;
}
void setuser_birth(String b)
{
user_birth=b;
}
void setuser_pwd(String p)
{
user_pwd = p;
}
String getuser_name()
{
return user_name;
}
int getuser_id()
{
return user_id;
}
// similarly u can write other get methods
}
import java.io.*;
import java.util.*;
class storeDetails
{
public static void main(String[] args)
{
userDetails info = new userDetails();
info.setuser_name(" srikanth");
info.setuser_id(10);
info.setuser_birth("21-08-77");
info.setuser_pwd("sreek");
Hashtable user = new Hashtable();
user.put(info.getuser_name(),info);
System.out.println(user);
}
}
cheers,
Srikanth