java List排序工具类
使用示例:
new OrderUtils().order(
list, "name", OrderUtils.DESC);
相关实例代码:
public static void main(String[] args) {
List list = getData(); // 获取无序数据
new OrderUtils().order(
list, "name", OrderUtils.DESC); //
排序
for (Person p :
list) {
System.out.println(p.toString());
}
}
private static
List getData(){
// 构造多个person对象为
排序提供数据
Person person = new Person();
person.setName("wtt");
person.setSex("男");
person.setAge(24);
Person person1 = new Person();
person1.setName("wjj");
person1.setSex("女");
person1.setAge(22);
Person person2 = new Person();
person2.setName("zqq");
person2.setSex("男");
person2.setAge(26);
Person person3 = new Person();
person3.setName("zb");
person3.setSex("男");
person3.setAge(23);
Person person4 = new Person();
person4.setName("cys");
person4.setSex("女");
person4.setAge(25);
List list = new Array
List();
list.add(person);
list.add(person1);
list.add(person2);
list.add(person3);
list.add(person4);
return
list;