Java排序Bean对象

List<ResumeWorkedExperience> wl= a.getWorkedExperiences();
    Comparator workedExperiences  = new ResumeContactComparator();
    Collections.sort(wl,workedExperiences);



ResumeContactComparator类:  1: 大于 0:等于 -1:小于


public class ResumeContactComparator implements Comparator<Object> {
public int compare(Object o1, Object o2) {
  if (o1 instanceof ResumeWorkedExperience
    && o2 instanceof ResumeWorkedExperience) {
   ResumeWorkedExperience o3 = (ResumeWorkedExperience) o1;
   ResumeWorkedExperience o4 = (ResumeWorkedExperience) o2;
   if (Integer.valueOf(o3.getFromYear()) == Integer.valueOf(o4.getFromYear())) {
    if(Integer.valueOf(o3.getFromMonth())<Integer.valueOf(o4.getFromMonth())){
     return 1;
    }else {
     return -1;
    }
   } else if(Integer.valueOf(o3.getFromYear()) < Integer.valueOf(o4.getFromYear())){
    return 1;
   }else{
    return -1;
   }
  }
  return 1;
}
}

你可能感兴趣的:(Java排序)