根据map中的某一key进行排序(快速排序实现)
/** * @author Gaoxl * 根据key值排序,要求key值能够转为Long类型(快速排序) * @param maps * @param key * @return */ public static void sort(Map<String,Object>[] maps,String key,int start,int end){ if(start < end){ int mid = divide(maps,key,start,end); sort(maps,key,start,mid - 1); sort(maps,key,mid + 1,end); } } private static int divide(Map<String,Object>[] m ,String key, int start,int end){ int mid = (start + end) / 2; Map<String,Object> midValue = m[mid];//取中间位置值作为排序关键 m[mid] = m[start]; while(start < end){ while(start < end && (Long)m[end].get(key) >= (Long)midValue.get(key)) --end; if(end > start){ m[start] = m[end]; ++ start; } while(start < end && (Long)m[start].get(key) <= (Long)midValue.get(key)) ++start; if(start < end){ m[end] = m[start]; -- end; } } m[start] = midValue; return start; }