I have an ArrayList
, a Collection class of Java, as follows:
ArrayList animals = new ArrayList();
animals.add(\"bat\
List lst = new ArrayList();
lst.add("Ram");
lst.add("Ram");
lst.add("Shiv");
lst.add("Boss");
Map mp = new HashMap();
for (String string : lst) {
if(mp.keySet().contains(string))
{
mp.put(string, mp.get(string)+1);
}else
{
mp.put(string, 1);
}
}
System.out.println("=mp="+mp);
Output:
=mp= {Ram=2, Boss=1, Shiv=1}