我是这个数据结构的新手。我无法从HashMap获取键的输入值。
public class Patient {
public String name,insurance;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getInsurance() {
return insurance;
}
public void setInsurance(String insurance) {
this.insurance = insurance;
}
我有一个HashMap的类管理员,它将字符串作为键,Object Patient作为值。输入名称和保险的值,并将其放在HashMap中。
public class Administrator{
public Administrator() {
}
HashMap <String,Patient> hashMap = new HashMap <String,Patient>();
static Patient patient = new Patient();
public void PatientInfo(){
String patientName = 'User input'
String insurance = 'User input'
patient.setName(patientName);
patient.setInsurance(insurance);
hashMap.put(patient.getName(),patient);
}
}
(我输入值jay,aetna和rod,Metroplus)
另一个名为PatientList的类,它将列出输入的名称和保险列表。
public class PatientList{
public PatientList(){}
public static table(Map<String,Patient>map){
for (Map.Entry<String, Patient>entry : map.entrySet()){
System.Out.println(entry.getKey(),entry.getValue().getInsurance());
///It prints jay aetna,rod aetna
///It prints same value for both different key.
{
}