1.List<Map<String,Object>>集合排序
/**
* List<Map<String,Object>>集合排序
*/
public List<Map<String, Object>> sortList(List<Map<String, Object>> list){
Collections.sort(list,new Comparator<Map>() {
@Override
public int compare(Map o1, Map o2) {
int ret = 0;
//比较两个对象的顺序,如果前者小于、等于或者大于后者,则分别返回-1/0/1,顺序o1.compareTo(o2),逆序o2.compareTo(o1)
ret = new Integer(o2.get("zhdf").toString()).compareTo(Integer.parseInt(o1.get("zhdf").toString()));
return ret;
}
});
return list;
}
2.List<Map<String,Object>>集合分页
/**
* List<Map<String,Object>>分页
* @param pageIndex:当前页码
* @param pageSize:每页显示记录数
*/
public List<Map<String, Object>> pageList(List<Map<String, Object>> list,int pageIndex,int pageSize){
int startIndex = (pageIndex - 1) * pageSize;
int lastIndex = pageIndex * pageSize;
int count = list.size();
if (lastIndex >= count) {
lastIndex = count;
}
return list.subList(startIndex, lastIndex);
}