如何使用java根据日期按月分组并计算总数?如何使用java根据日期按月分组并计算总数?
public static void main(String[] args) {
Map<String, Object>out=new HashMap<String, Object>();
Map<String,Object> hm=new HashMap<String, Object>();
List<String> al= new ArrayList<String>();
al.add("51b6f5fde4b0dd92df2c3270");
al.add("51b866e9e4b021170dd1ae1c");
hm.put("sDate","02-Oct-2015");
hm.put("status","S");
hm.put("SMSSentId", al);
out.put("Student1", hm);
Map<String,Object> hm1=new HashMap<String, Object>();
List<String> al1= new ArrayList<String>();
al1.add("51b6f5fde4b0dd92df2c3271");
al1.add("51b866e9e4b021170dd1ae12");
hm1.put("sDate","03-Oct-2015");
hm1.put("status","S");
hm1.put("SMSSentId", al1);
out.put("Student2", hm1);
Map<String,Object> hm2=new HashMap<String, Object>();
List<String> al2= new ArrayList<String>();
al2.add("51b6f5fde4b0dd92df2c3271");
hm2.put("sDate","03-Oct-2016");//Year changed
hm2.put("status","S");
hm2.put("SMSSentId", al2);
out.put("Student3", hm2);
//System.out.println(out);
for (Map.Entry<String, Object> entry : out.entrySet())
{
// System.out.println(entry.getKey() + "/" + entry.getValue());
for (Map.Entry<String, Object> entry1 : hm.entrySet())
{
System.out.println(entry1.getKey() + "/" + entry1.getValue());
if(entry1.getKey().equals("SMSSentId"))
{
int a= ((List<String>) entry1.getValue()).size();
System.out.println(a);
}
}
}
}
我不知道如何修改此地图和list.Please给我建议它以正确的方式或不 或任何其他比较方法
我预计今年产量
# | Month | Year | TotalSMSSent
1 Oct 2015 4
2 Oct 2016 1
为什么要创建3个HashMap实例? 'hm,hm1,hm2'?然后只遍历'hm'? –
你能帮我修改吗? –
其实我想比较日期和基于我想要计算总SMSSentId,如果它是相同的月份和同一年 –