先创建一个List集合
List
打印该List集合,结果为
[{code=ays5h2, name=孙悟空, age=600}, {code=brse7f, name=猪八戒, age=700}, {code=brse7f, name=唐僧, age=42}, {code=twdf0, name=沙悟净, age=650}]
1、根据code和name正序排序
Collections.sort(list, new Comparator
打印结果:[{code=ays5h2, name=孙悟空, age=600}, {code=brse7f, name=唐僧, age=42}, {code=brse7f, name=猪八戒, age=700}, {code=twdf0, name=沙悟净, age=650}]
2、code正序排序,name倒叙排序
Collections.sort(list, new Comparator
打印结果:[{code=ays5h2, name=孙悟空, age=600}, {code=brse7f, name=猪八戒, age=700}, {code=brse7f, name=唐僧, age=42}, {code=twdf0, name=沙悟净, age=650}]