Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Before I talk about the difference between a Pair and a HashMap, let me tell you why that's not really the question you want answered. What you really want to know is why would you take an Object and break it into a list of key/value primitivies.</p> <p>The code you are referencing is converting from an object oriented approach of using a class <code>Patient</code> (which really looks like it should be called <code>PatientInfo</code>) into a list of primitives, they are essentialy "deObjectOrienting" the class.</p> <p>So in their model each class variable becomes a <code>Pair</code> where the variable name become the key, and the variable value become the value.</p> <p>Here is an expanded example class</p> <pre><code>// Old style (Object oriented) class PatientInfo{ String religion; String address; } PatientInfo patientInfo = new PatientInfo(); patientInfo.setReligion("myReligionName"); patientInfo.setAddress("address of the patient"); // New Style, key/value primitive pairs (very not object oriented) Pair&lt;String,String&gt; religionInfo = new Pair&lt;String,String&gt;("religion","myReligionName"); Pair&lt;String,String&gt; addressInfo = new Pair&lt;String,String&gt;("address","address of the patient"); </code></pre> <p>They then add these either the <code>Patient</code> or the <code>Pair</code> into a List.</p> <p>Why would someone do this is a good question. Most people try to become more object oriented as it makes coding easier. Perhaps since it's only a single variable in the Clss they figured why not remove the class entirely?</p> <p>To your original question between a Pair and a HashMap. A Pair is just a key/value. A HashMap is the collection usually used to store many key/value pairs. Here they are using a List where they should probably be using the HashMap.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload