1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class SortMapOnKeyStringExample {
public Sess sess ;
public TreeMap<String, Sess> myTreeMap= new TreeMap<String, Sess>(Collections.reverseOrder());
public SortMapOnKeyStringExample(){
}
public static <T> void main(String[] args) {
String date1 = "10/12/2014";
String date2 = "05/12/2014";
String date3 = "15/12/2015";
String date4 = "05/12/2013";
Sess s1= new Sess(date1, "2");
Sess s2= new Sess(date2, "3");
Sess s3= new Sess(date3, "1");
Sess s4= new Sess(date4, "4");
SortMapOnKeyStringExample sortEx= new SortMapOnKeyStringExample();
sortEx.myTreeMap.put("52", s1);
sortEx.myTreeMap.put("87", s2);
sortEx.myTreeMap.put("65", s3);
sortEx.myTreeMap.put("54", s4);
printMap(sortEx.myTreeMap);
}
public TreeMap<String, Sess> getReverseOrderTreeMap(TreeMap<String, Sess> sess){
TreeMap<String, Sess> result=null;
return result;
}
public static void printMap(Map<String, Sess> map) {
for (Map.Entry<String, Sess> entry : map.entrySet()) {
System.out.println(entry.getKey()
+ " ---->" + entry.getValue().dateEffet +"---->"+ entry.getValue().description );
}
}
} |
Partager