This should do it:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
ArrayList<Date> dates = new ArrayList<Date>();
dates.add(sdf.parse("11/06/2013"));//Tuesday
dates.add(sdf.parse("15/06/2013"));//Saturday
dates.add(sdf.parse("17/06/2013"));//Monday
dates.add(sdf.parse("18/06/2013"));//Tuesday
dates.add(sdf.parse("22/06/2013"));//Saturday
dates.add(sdf.parse("25/06/2013"));//Tuesday
System.out.println(checkDay(dates , "Mon"));
System.out.println(checkDay(dates , "Tue"));
System.out.println(checkDay(dates , "Wed"));
System.out.println(checkDay(dates , "Sat"));
public int checkDay(ArrayList<Date> list, String day)
{
int count = 0;
SimpleDateFormat sdf = new SimpleDateFormat("EE");
for(Date d : list)
{
if(sdf.format(d).equals(day))
count++;
}
return count;
}
See it working here:
http://ideone.com/SdM5Tr
If you plan to do it multiple times however, you'd be better running it once and storing the counts in a hashmap:
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
ArrayList<Date> dates = new ArrayList<Date>();
dates.add(sdf.parse("11/06/2013"));//Tuesday
dates.add(sdf.parse("15/06/2013"));//Saturday
dates.add(sdf.parse("17/06/2013"));//Monday
dates.add(sdf.parse("18/06/2013"));//Tuesday
dates.add(sdf.parse("22/06/2013"));//Saturday
dates.add(sdf.parse("25/06/2013"));//Tuesday
HashMap counts = getCounts(dates);
System.out.println(counts.get("Mon"));
System.out.println(counts.get("Tue"));
public static HashMap getCounts(ArrayList<Date> list)
{
HashMap counts = new HashMap();
SimpleDateFormat sdf = new SimpleDateFormat("EE");
for(Date d : list)
{
String form = sdf.format(d);
if(counts.containsKey(form))
counts.put(form,((int)counts.get(form))+1);
else
counts.put(form,1);
}
return counts;
}
See it here:
http://ideone.com/SdM5Tr