java 比较器

1:先看实现类

package compare_sort;

import java.util.Comparator;

import domain.XzfwServiceBase;

public class ServiceBaseSort implements Comparator  {

	public int compare(Object o1, Object o2) {
		  // TODO Auto-generated method stub
		XzfwServiceBase c1 = (XzfwServiceBase) o1;
		XzfwServiceBase c2 = (XzfwServiceBase) o2;
		  if ( Long.valueOf(c1.getItemid())>Long.valueOf(c2.getItemid())) {
		   return 1;
		  } else  if (Long.valueOf(c1.getItemid())<Long.valueOf(c2.getItemid())) {
		    return -1;
		   } else {
		    return 0;
		   }

		  }

}

 

2:在看引入方法

ServiceBaseSort sbsort=new ServiceBaseSort();
        	java.util.Collections.sort(mySQList, sbsort);

 

List 里面都是 XzfwServiceBase  的对象

你可能感兴趣的:(java)