This below code checks id exist in ArrayList or not & then add it to map.
List<Map<Object, Object>> myListOfMaps = new ArrayList<Map<Object, Object>>();
ArrayList<String> al1 = new ArrayList<String>();
al1.add("92");
al1.add("94");
al1.add("91");
al1.add("98");
Map<Object,Object> map = new HashMap<Object,Object>();
ArrayList<String> result = new ArrayList<String>();
String id = "95,98,94";
for(int i=0;i<al1.size();i++)
{
if(id.contains(al1.get(i)))
{
result.add("true");
map.put("Access", true);
}
else
{
result.add("false");
map.put("Access", false);
}
myListOfMaps.add(map);
}
for (int i = 0 ; i < myListOfMaps.size() ; i++) {
Map<Object, Object> myMap = myListOfMaps.get(i);
for (Entry<Object, Object> entrySet : myMap.entrySet()) {
System.out.println("Key = " + entrySet.getKey() + " , Value = " + entrySet.getValue());
}
}
System.out.println(result);
output
Key = Access , Value = true
Key = Access , Value = true
Key = Access , Value = true
Key = Access , Value = true
[false, true, false, true]
arraylist result is fine but mapvalues returning true only.Please help me how to add k,v to map based on condition so that mapresult looks like this [{Access=false},{Access=true},{Access=false},{Access=true}].