I have the following ArrayList which I fill with information from a database
ArrayList<HashMap<String, String>> employeeList;
employeeList = new ArrayList<>();
private static final String TAG_NAME = "name";
public static final String TAG_DESIGNATION = "designation";
Log.d("INICIA ","employeeList= "+employeeList);
In the Logcat it gives me the following:
D/INICIA: employeeList= [{designation=manager, name=rick}]
Everything works fine but I have a doubt how I could access the value manager
found in the arrayList to be able to use it in a condition
A. If there is only one pair of values
It is enough to obtain said value by the name of its key in the HashMap that you have created. The get(0) looks for the first (and in this case only) value within the map:
The variable
sDesignation
will have the valuemanager
in this case.B. If there are multiple pairs of values in the map
If there are several pairs of values in the array, reading is usually done within a loop (for, while...).
Example with Iterator and While :
example with for loop
According to your ArrayList, it contains a HashMap with keys
designation
andname
:You can get the values by index