---
title: "排序一个list数组中的元素"
author: "yangbinfc"
date: "2011-03-01T19:04:00Z"
tags: []
slug: "list"
draft: false
lastmod: "2012-11-04T17:47:38Z"
id: 1715357
url: "https://yangbinfc.iteye.com/blog/1715357"
---

1：动态的获得方法 如：getUserId

2：动态的调用方法 如：method1.invoke((E)a,null)

sort里面的compareto方法，里面如果返回时-1 就不把object a ，b 调换 ，如果要倒叙排序好办法就是把 返回的值编程整的 ，可以把内部比较的时候用 b - a ，这样返回正数， 就巧妙的实现了倒叙了 ，It is amazing

边学便用 今天学了得到Method的方法 以后就可以这样用了 Method m11=(a).getClass(I).getMethod(method,null

);

Collections.sort(list, new Comparator() {  
int ret = 0;  
public int compare(Object o1, Object o2) {

}

中如果compare 方法返回时-1 ，则不会调换o1 o2顺序，如果放回为1，则会调换o1 o2顺序