阅读背景:

根据Map中的key进行排序

来源:互联网 
@Test
public void testFindLwdr() {
String idxcd = "A,B,C,D,E,F,G";
String[] split = idxcd.split(",");

List<CommIdxNumber> weeklyRising = commIdxNumberWeekDao
.getWeeklyRising(split);
Map<Double, String> mapValue = new TreeMap<Double, String>();
for (CommIdxNumber commIdxNumber : weeklyRising) {
mapValue.put(commIdxNumber.getLwdr(), commIdxNumber.getIdxcd());
}
Map<Double, String> resultMap = sortMapByKey(mapValue);
System.out.println(resultMap);


}


public static Map<Double, String> sortMapByKey(Map<Double, String> map) {
Map<Double , String> resultMap = new HashMap<Double , String>();
String strValue = "";
Double key = null;
if (map == null || map.isEmpty()) {
return null;
}
Map<Double, String> sortMap = new TreeMap<Double, String>(
new Comparator<Double>() {


@Override
public int compare(Double o1, Double o2) {
return o2.compareTo(o1);
}


});
sortMap.putAll(map);
for (Entry<Double, String> entry : sortMap.entrySet()) {
strValue = entry.getValue();
key = entry.getKey();
if (strValue != null) {
break;
}
}
resultMap.put(key, strValue);
return resultMap;
}@Test
public void testFindLwdr() {
String idxcd



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: