java map 怎么按按key排序
2个回答
展开全部
java中map按照double大小进行排序,可以使用collentions接口的sort方法进行比较,实例如下:
Collections.sort(dataMap, new Comparator<Map<String, Object>>() { @Override public int compare(Map<String, Object> lhs, Map<String, Object> rhs) { Double d5 = ((Double) rhs.get(OpenPrice)); Double d6 = (Double) lhs.get(OpenPrice); if (d5 != null && d6 != null) { return d5.compareTo(d6); } else { return flag; } // return d1.compareTo(d2);}
根据返回的int类型,可设置按照从大到小还是从小到大排序
Collections.sort(dataMap, new Comparator<Map<String, Object>>() { @Override public int compare(Map<String, Object> lhs, Map<String, Object> rhs) { Double d5 = ((Double) rhs.get(OpenPrice)); Double d6 = (Double) lhs.get(OpenPrice); if (d5 != null && d6 != null) { return d5.compareTo(d6); } else { return flag; } // return d1.compareTo(d2);}
根据返回的int类型,可设置按照从大到小还是从小到大排序
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询