List按内部存储的object的属性排序

来源:互联网 发布:广西机保数据采集系统 编辑:程序博客网 时间:2024/05/26 09:57

private List sortFieldListByRowIndex(List fieldList){
  Comparator<DynamicFormField> comparator = new Comparator<DynamicFormField>(){
   public int compare(DynamicFormField f1, DynamicFormField f2) {
     if(f1.getRowIndex()!=f2.getRowIndex()){
         return f1.getRowIndex()-f2.getRowIndex();
      }else if(f1.getColIndex()!=f2.getColIndex()){
       return f1.getColIndex()-f2.getColIndex();
      }else{
       return (int) (f1.getId() - f2.getId());
      }
   }
  };
  Collections.sort(fieldList, comparator);
  return fieldList;
 }
这是工作中 使用过的一个例子。
对fieldList中DynamicFormField对象 先按其rowIndex排序后按colIndex排序

原创粉丝点击