package core;
import java.text.NumberFormat;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
public class ListUtils {
/**
* 对list的元素按照多个属性名称排序,
* list元素的属性可以是数字(byte、short、int、long、float、double等,支持正数、负数、0)、char、String、java.util.Date
*
* @param lsit
* @param sortname list元素的属性名称
* @param isAsc true升序,false降序
*/
public static void sort(List list, final boolean isAsc, final String... sortnameArr) {
Collections.sort(list, new Comparator() {
public int compare(E a, E b) {
int ret = 0;
try {
for (int i = 0; i < sortnameArr.length; i++) {
ret = ListUtils.compareObject(sortnameArr[i], isAsc, a, b);
if (0 != ret) {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
});
}
/**
* 给list的每个属性都指定是升序还是降序
*
* @param list
* @param sortnameArr 参数数组
* @param typeArr 每个属性对应的升降序数组, true升序,false降序
*/
public static void sort(List list, final String[] sortnameArr, final boolean[] typeArr) {
if (sortnameArr.length != typeArr.length) {
throw new RuntimeException("属性数组元素个数和升降序数组元素个数不相等");
}
Collections.sort(list, new Comparator() {
public int compare(E a, E b) {
int ret = 0;
try {
for (int i = 0; i < sortnameArr.length; i++) {
ret = ListUtils.compareObject(sortnameArr[i], typeArr[i], a, b);
if (0 != ret) {
break;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return ret;
}
});
}
/**
* 对2个对象按照指定属性名称进行排序
*
* @param sortname 属性名称
* @param isAsc true升序,false降序
* @param a
* @param b
* @return
* @throws Exception
*/
private static int compareObject(final String sortname, final boolean isAsc, E a, E b) throws Exception {
int ret;
Object value1 = ListUtils.forceGetFieldValue(a, sortname);
Object value2 = ListUtils.forceGetFieldValue(b, sortname);
//有空值防止报错
if (value1!=null&&value2!=null){
String str1 = value1.toString();
String str2 = value2.toString();
if (value1 instanceof Number && value2 instanceof Number) {
int maxlen = Math.max(str1.length(), str2.length());
str1 = ListUtils.addZero2Str((Number) value1, maxlen);
str2 = ListUtils.addZero2Str((Number) value2, maxlen);
} else if (value1 instanceof Date && value2 instanceof Date) {
long time1 = ((Date) value1).getTime();
long time2 = ((Date) value2).getTime();
int maxlen = Long.toString(Math.max(time1, time2)).length();
str1 = ListUtils.addZero2Str(time1, maxlen);
str2 = ListUtils.addZero2Str(time2, maxlen);
}
if (isAsc) {
ret = str1.compareTo(str2);
} else {
ret = str2.compareTo(str1);
}
return ret;
}
return 0;
}
/**
* 给数字对象按照指定长度在左侧补0.
*
* 使用案例: addZero2Str(11,4) 返回 "0011", addZero2Str(-18,6)返回 "-000018"
*
* @param numObj 数字对象
* @param length 指定的长度
* @return
*/
public static String addZero2Str(Number numObj, int length) {
NumberFormat nf = NumberFormat.getInstance();
// 设置是否使用分组
nf.setGroupingUsed(false);
// 设置最大整数位数
nf.setMaximumIntegerDigits(length);
// 设置最小整数位数
nf.setMinimumIntegerDigits(length);
return nf.format(numObj);
}
/**
* 获取指定对象的指定属性值(去除private,protected的限制)
*
* @param obj 属性名称所在的对象
* @param fieldName 属性名称
* @return
* @throws Exception
*/
public static Object forceGetFieldValue(Object obj, String fieldName) throws Exception {
Field field = obj.getClass().getDeclaredField(fieldName);
Object object = null;
boolean accessible = field.isAccessible();
if (!accessible) {
// 如果是private,protected修饰的属性,需要修改为可以访问的
field.setAccessible(true);
object = field.get(obj);
// 还原private,protected属性的访问性质
field.setAccessible(accessible);
return object;
}
object = field.get(obj);
return object;
}
}
package PjectUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author yinaibang
*
*/
public class UserInfo implements java.io.Serializable {
private static final long serialVersionUID = -3522051445403971732L;
private Integer userId;
private String username;
private Date birthDate;
private Integer age;
private float fRate;
private char ch;
public Date getBirthDate() {
return birthDate;
}
public String getBirthDatestr() {
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
return formater.format(getBirthDate());
}
public UserInfo(Integer userId, String username, Date birthDate, Integer age, float fRate, char ch) {
super();
this.userId = userId;
this.username = username;
this.birthDate = birthDate;
this.age = age;
this.fRate = fRate;
this.ch = ch;
}
@Override
public String toString() {
return "UserInfo [userId=" + userId + ", \tusername=" + username + ", \tbirthDate=" + getBirthDatestr()
+ ", \tage=" + age + ", fRate=" + fRate + ", ch=" + ch + "]";
}
}
package models;
import core.ListUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author yinaibang
*
*/
public class ListUtilsTest {
public static void main(String[] args) throws Exception {
ListUtilsTest testObj = new ListUtilsTest();
List list = new ArrayList();
// public UserInfo(Integer userId, String username, Date birthDate,Integer age, float fRate, char ch)
SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
UserInfo user1 = new UserInfo(3, "bbb", formater.parse("1980-12-01"), 1, 1.2f, 'a');
UserInfo user2 = new UserInfo(0, "126", formater.parse("1900-10-11"), 03, -3.6f, 'c');
UserInfo user3 = new UserInfo(12, "5", formater.parse("1973-08-21"), 15, 9.32f, 'f');
UserInfo user4 = new UserInfo(465, "1567", formater.parse("2012-01-26"), 20, 12.56f, '0');
UserInfo user5 = new UserInfo(2006, "&4m", formater.parse("2010-05-08"), 100, 165.32f, '5');
UserInfo user6 = new UserInfo(5487, "hf67", formater.parse("2016-12-30"), 103, 56.32f, 'm');
UserInfo user7 = new UserInfo(5487,"jigg", formater.parse("2000-10-16"), 103, 56.32f, 'm');
UserInfo user8 = new UserInfo(5487, "jigg", formater.parse("1987-07-25"), 103, 56.32f, 'm');
list.add(user1);
list.add(user2);
list.add(user3);
list.add(user4);
list.add(user5);
list.add(user6);
list.add(user7);
list.add(user8);
System.out.println("\n-------原来序列-------------------");
testObj.printfUserInfoList(list);
// 按userId升序、username降序、birthDate升序排序
String [] sortNameArr = {"userId","username","birthDate"};
boolean [] isAscArr = {true,false,true};
ListUtils.sort(list,sortNameArr,isAscArr);
System.out.println("\n--------按按userId升序、username降序、birthDate升序排序(如果userId相同,则按照username降序,如果username相同,则按照birthDate升序)------------------");
testObj.printfUserInfoList(list);
// 按userId、username、birthDate都升序排序
ListUtils.sort(list, true, "userId", "username","birthDate");
System.out.println("\n--------按userId、username、birthDate排序(如果userId相同,则按照username升序,如果username相同,则按照birthDate升序)------------------");
testObj.printfUserInfoList(list);
// 按userId、username都倒序排序
ListUtils.sort(list, false, "userId", "username");
System.out.println("\n--------按userId和username倒序(如果userId相同,则按照username倒序)------------------");
testObj.printfUserInfoList(list);
// 按username、birthDate都升序排序
ListUtils.sort(list, true, "username", "birthDate");
System.out.println("\n---------按username、birthDate升序(如果username相同,则按照birthDate升序)-----------------");
testObj.printfUserInfoList(list);
// 按birthDate倒序排序
ListUtils.sort(list, false, "birthDate");
System.out.println("\n---------按birthDate倒序-----------------");
testObj.printfUserInfoList(list);
// 按fRate升序排序
ListUtils.sort(list, true, "fRate");
System.out.println("\n---------按fRate升序-----------------");
testObj.printfUserInfoList(list);
// 按ch倒序排序
ListUtils.sort(list, false, "ch");
System.out.println("\n---------按ch倒序-----------------");
testObj.printfUserInfoList(list);
}
private void printfUserInfoList(List list) {
for (UserInfo user : list) {
System.out.println(user.toString());
}
}
}
"C:\Program Files\Java\jdk1.8.0_40\bin\java.exe" "-javaagent:D:\Sofwere\IntelliJ IDEA 2018.3.5\lib\idea_rt.jar=51043:D:\Sofwere\IntelliJ IDEA 2018.3.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_40\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_40\jre\lib\rt.jar;D:\project\lesson-master\lesson\tmp\classes\production\lesson;D:\project\lesson-master\lesson\lib\Msc.jar;D:\project\lesson-master\lesson\lib\smssdk.jar;D:\project\lesson-master\lesson\lib\jedis-2.9.0.jar;D:\project\lesson-master\lesson\lib\json_jdk1.7.jar;D:\project\lesson-master\lesson\lib\kaptcha-2.3.2.jar;D:\project\lesson-master\lesson\lib\httpcore-4.4.1.jar;D:\project\lesson-master\lesson\lib\httpmime-4.3.4.jar;D:\project\lesson-master\lesson\lib\pinyin4j-2.5.0.jar;D:\project\lesson-master\lesson\lib\xmlbeans-2.6.0.jar;D:\project\lesson-master\lesson\lib\httpclient-4.4.1.jar;D:\project\lesson-master\lesson\lib\playweixin-1.0.0.jar;D:\project\lesson-master\lesson\lib\zxing-core-3.3.0.jar;D:\project\lesson-master\lesson\lib\poi-3.14-20160307.jar;D:\project\lesson-master\lesson\lib\commons-dbutils-1.6.jar;D:\project\lesson-master\lesson\lib\commons-pool2-2.4.2.jar;D:\project\lesson-master\lesson\lib\aliyun-sdk-oss-2.2.1.jar;D:\project\lesson-master\lesson\lib\commons-httpclient-3.1.jar;D:\project\lesson-master\lesson\lib\httpclient-cache-4.3.4.jar;D:\project\lesson-master\lesson\lib\poi-ooxml-3.14-20160307.jar;D:\project\lesson-master\lesson\lib\poi-ooxml-schemas-3.14-20160307.jar;D:\play-1.4.2\modules\docviewer\lib\play-docviewer.jar;D:\play-1.4.2\framework\lib\ivy-2.4.0.jar;D:\play-1.4.2\framework\lib\oval-1.85.jar;D:\play-1.4.2\framework\lib\c3p0-0.9.5.jar;D:\play-1.4.2\framework\lib\gson-2.6.2.jar;D:\play-1.4.2\framework\lib\h2-1.4.185.jar;D:\play-1.4.2\framework\lib\jamon-2.81.jar;D:\play-1.4.2\framework\lib\jj-imaging.jar;D:\play-1.4.2\framework\lib\jj-textile.jar;D:\play-1.4.2\framework\lib\junit-4.12.jar;D:\play-1.4.2\framework\lib\mail-1.4.7.jar;D:\play-1.4.2\framework\lib\antlr-2.7.7.jar;D:\play-1.4.2\framework\lib\cglib-3.2.1.jar;D:\play-1.4.2\framework\lib\dom4j-1.6.1.jar;D:\play-1.4.2\framework\lib\jaxen-1.1.6.jar;D:\play-1.4.2\framework\lib\jj-wikitext.jar;D:\play-1.4.2\framework\lib\log4j-1.2.17.jar;D:\play-1.4.2\framework\lib\asm-all-5.0.4.jar;D:\play-1.4.2\framework\lib\ezmorph-1.0.6.jar;D:\play-1.4.2\framework\lib\jregex-1.2_01.jar;D:\play-1.4.2\framework\lib\xstream-1.4.8.jar;D:\play-1.4.2\framework\lib\commons-io-2.4.jar;D:\play-1.4.2\framework\lib\postgresql-9.0.jar;D:\play-1.4.2\framework\lib\snakeyaml-1.17.jar;D:\play-1.4.2\framework\lib\joda-time-2.9.2.jar;D:\play-1.4.2\framework\lib\jsr107cache-1.0.jar;D:\play-1.4.2\framework\lib\xmlpull-1.1.3.1.jar;D:\play-1.4.2\framework\lib\activation-1.1.1.jar;D:\play-1.4.2\framework\lib\commons-lang-2.6.jar;D:\play-1.4.2\framework\lib\groovy-all-2.4.6.jar;D:\play-1.4.2\framework\lib\javax.inject-1.0.jar;D:\play-1.4.2\framework\lib\jj-simplecaptcha.jar;D:\play-1.4.2\framework\lib\slf4j-api-1.7.16.jar;D:\play-1.4.2\framework\lib\bcprov-jdk15-1.45.jar;D:\play-1.4.2\framework\lib\commons-email-1.4.jar;D:\play-1.4.2\framework\lib\hamcrest-core-1.3.jar;D:\play-1.4.2\framework\lib\commons-codec-1.10.jar;D:\play-1.4.2\framework\lib\netty-3.10.4.Final.jar;D:\play-1.4.2\framework\lib\commons-logging-1.2.jar;D:\play-1.4.2\framework\lib\ehcache-core-2.6.11.jar;D:\play-1.4.2\framework\lib\javassist-3.20.0-GA.jar;D:\play-1.4.2\framework\lib\spymemcached-2.12.0.jar;D:\play-1.4.2\framework\lib\slf4j-log4j12-1.7.16.jar;D:\play-1.4.2\framework\lib\signpost-core-1.2.1.2.jar;D:\play-1.4.2\framework\lib\jboss-logging-3.1.0.GA.jar;D:\play-1.4.2\framework\lib\commons-beanutils-1.9.2.jar;D:\play-1.4.2\framework\lib\validation-api-1.0.0.GA.jar;D:\play-1.4.2\framework\lib\async-http-client-1.9.31.jar;D:\play-1.4.2\framework\lib\commons-fileupload-1.3.1.jar;D:\play-1.4.2\framework\lib\commons-javaflow-1590792.jar;D:\play-1.4.2\framework\lib\commons-collections-3.2.2.jar;D:\play-1.4.2\framework\lib\mchange-commons-java-0.2.9.jar;D:\play-1.4.2\framework\lib\hibernate-c3p0-4.2.19.Final.jar;D:\play-1.4.2\framework\lib\hibernate-core-4.2.19.Final.jar;D:\play-1.4.2\framework\lib\mysql-connector-java-5.1.35.jar;D:\play-1.4.2\framework\lib\c3p0-oracle-thin-extras-0.9.5.jar;D:\play-1.4.2\framework\lib\geronimo-servlet_2.5_spec-1.2.jar;D:\play-1.4.2\framework\lib\hibernate-ehcache-4.2.19.Final.jar;D:\play-1.4.2\framework\lib\hibernate-validator-4.1.0.Final.jar;D:\play-1.4.2\framework\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;D:\play-1.4.2\framework\lib\hibernate-entitymanager-4.2.19.Final.jar;D:\play-1.4.2\framework\lib\hibernate-commons-annotations-4.0.2.Final.jar;D:\play-1.4.2\framework\lib\jboss-transaction-api_1.1_spec-1.0.1.Final.jar;D:\play-1.4.2\framework\lib\org.eclipse.jdt.core-3.10.0.v20140604-1726.jar;D:\play-1.4.2\framework\play-1.4.2.jar" models.ListUtilsTest
-------原来序列-------------------
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
--------按按userId升序、username降序、birthDate升序排序(如果userId相同,则按照username降序,如果username相同,则按照birthDate升序)------------------
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
--------按userId、username、birthDate排序(如果userId相同,则按照username升序,如果username相同,则按照birthDate升序)------------------
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
--------按userId和username倒序(如果userId相同,则按照username倒序)------------------
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
---------按username、birthDate升序(如果username相同,则按照birthDate升序)-----------------
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
---------按birthDate倒序-----------------
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
---------按fRate升序-----------------
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
---------按ch倒序-----------------
UserInfo [userId=5487, username=hf67, birthDate=2016-12-30, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=2000-10-16, age=103, fRate=56.32, ch=m]
UserInfo [userId=5487, username=jigg, birthDate=1987-07-25, age=103, fRate=56.32, ch=m]
UserInfo [userId=12, username=5, birthDate=1973-08-21, age=15, fRate=9.32, ch=f]
UserInfo [userId=0, username=126, birthDate=1900-10-11, age=3, fRate=-3.6, ch=c]
UserInfo [userId=3, username=bbb, birthDate=1980-12-01, age=1, fRate=1.2, ch=a]
UserInfo [userId=2006, username=&4m, birthDate=2010-05-08, age=100, fRate=165.32, ch=5]
UserInfo [userId=465, username=1567, birthDate=2012-01-26, age=20, fRate=12.56, ch=0]
Process finished with exit code 0