public static void main(String[] args) { List<Map> integerList = new ArrayList<>(); Map map = new HashMap(); map.put("jsvalue",132.2); map.put("jsname","13234"); Map map3 = new HashMap(); map3.put("jsvalue",12.2); map3.put("jsname","132"); Map map1 = new HashMap(); map1.put("jsvalue",132.3); map1.put("jsname","133"); integerList.add(map); integerList.add(map1); integerList.add(map3); List<BigDecimal> decimals= new ArrayList<>(); for(Map mapfor :integerList){ decimals.add(new BigDecimal( mapfor.get("jsvalue")+"")); } Collections.sort(decimals); List list = new ArrayList(); for(BigDecimal bigDecimal:decimals){ for(Map mapfor :integerList){ if( bigDecimal.equals(new BigDecimal( mapfor.get("jsvalue")+""))){ list.add(mapfor); } } } System.out.println(list.subList(0,2)); }
list集合中是map值 倒叙排序取前两个
最新推荐文章于 2024-05-14 08:45:10 发布