-1

我有一个有价值的患者 ID,它是我从应用程序的后端获取的,如下所示

 String PatientId = rxDetails.getPatient().getPatientID() ; //patient ID recieved from backend

这是另一个存储详细信息的地图,如下所示

 Map <String ,List<String>> m = new LinkedHashMap LinkedHashMap<String,List<String>>();
  List<String> info = new ArrayList<String>();
                info.add("ScriptInfo");
                info.add("Name");
                info.add("PhoneNo");
  m.put(PatientID ,info);
  transaction.setValue(ITransaction.PATIENT_DETAILS_FOR_CCV, ppvdetails);//please ignore this line as it is my framework dependent and in this line I am storing the Map

如图所示,它还存储了患者 ID

现在我的查询是我必须在某些条件下交叉检查我从后端获得的患者 ID 第一个是否已经存在于 Map m 中

现在如下所示,我在另一个名为 ValidatedPatientList 的 Map 中引用 Map m

Map ValidatedPatientList = (LinkedHashMap)transaction.getValue(ITransaction.VALIDATED_CCV_PH_NBR);//please ignore this line as it is my framework dependent and in this line I am retreving the Mao
if(ValidatedPatientList != null && !ValidatedPatientList.isEmpty())
      {
       Iterator iterator = ValidatedPatientList.keySet().iterator();
          if(iterator.hasNext())
          {

如上所示现在我必须先提取 ValidatedPatientList 的所有键,然后必须比较它是否包含第一个患者 id,请告知如何实现这一点..!!

4

1 回答 1

1

使用HashMap#containsKey. 如果映射包含指定键的映射,它将返回 true。

Javadoc 用于java.util.HashMap

/**
 * Returns <tt>true</tt> if this map contains a mapping for the
 * specified key.
 *
 * @param   key   The key whose presence in this map is to be tested
 * @return <tt>true</tt> if this map contains a mapping for the specified
 * key.
 */
public boolean containsKey(Object key) {
    return getEntry(key) != null;
}

代码示例:

Map<String ,List<String ValidatedPatientList = (LinkedHashMap<String ,List<String)transaction.getValue(ITransaction.VALIDATED_CCV_PH_NBR);
if(ValidatedPatientList != null && !ValidatedPatientList.isEmpty())
{  
   if (validatedPatientList.containsKey(patientId)) //returns true if map contains the key
   {...}
}
于 2013-01-05T12:35:17.697 回答