我有以下场景:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
System.out.println(dateFormat.parse("31/05/2011"));
Run Code Online (Sandbox Code Playgroud)
给出一个输出
Tue May 31 00:00:00 SGT 2011
Run Code Online (Sandbox Code Playgroud)
但我想要输出
31/05/2011
Run Code Online (Sandbox Code Playgroud)
我需要在这里使用解析,因为日期需要按日期排序而不是字符串.
有任何想法吗 ??
我有一个hashMap,它具有以下值作为密钥value(sql date , integer)对:
a.put("31-05-2011",67);
a.put("01-06-2011",89);
a.put("10-06-2011",56);
a.put("25-05-2011",34);
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下键对hashMap进行排序时:Map modified_a = new TreeMap(a); 并按如下方式显示按键:
01-06-2011,10-06-2011,25-05-2011, 31-05-2011
Run Code Online (Sandbox Code Playgroud)
但我希望按键排序为
31-05-2011,25-05-2011,01-06-2011 ,10-06-2011
Run Code Online (Sandbox Code Playgroud)
我可以看到值是根据前2位数(这是日期值)进行排序的,但是我还要考虑月份值,并根据月份排序,然后按月对每个月进行排序.任何线索?
我有一个场景,我有多个HashMap对象需要存储在同一个文本文件中.例如 :
a.put("01jan", 13);
a.put("02feb", 13);
a.put("03march", 13);
a.put("04apr", 13);
a.put("05may", 13);
b.put("06june", 12);
b.put("07july", 12);
b.put("08aug", 12);
b.put("09sept", 12);
b.put("10oct", 12);
Run Code Online (Sandbox Code Playgroud)
我想使用java序列化将对象保存在同一个txt文件中.有没有办法做到这一个接一个我尝试使用FileOutputStream( file_name,true).此外,当我尝试检索对象说HashMap b现在和HashMap a需要时.有没有办法实现这个目标?如何检索out of order对象并检索正确的对象?
谢谢,Bhavya