当先锋百科网

首页 1 2 3 4 5 6 7
List<Map<String, Object>> list=new ArrayList<>();
	Map map1=new HashMap();
	map1.put("name","张三");
	map1.put("age",12);
	map1.put("sex","男");
	
	Map map2=new HashMap();
	map2.put("name","李四");
	map2.put("age",13);
	map2.put("sex","女");

Collections.sort(list, new Comparator<Map<String, Object>>() {
				public int compare(Map<String, Object> o1, Map<String, Object> o2) {
					Integer age1= Integer.parseInt(o1.get("age").toString()) ;
					Integer age2 = Integer.parseInt(o1.get("age").toString()) ;

					return age2 .compareTo(age1);//倒序
					
					//return age1.compareTo(age2);//升序
				}
			});