Java sorts list collections sort()

Sort the objects in a collection, and sort them in ascending or descending order according to the size of an indicator of the object. The code is as follows:

Arrange in descending order

Sort in ascending order

After testing, it is found that you only need to change the positions of the two objects in ascending or descending order.

If the indicators are the same, you need to create a comparator to sort according to multiple indicators:

Reverse output the list set:

Collections. reverse(list);

Resulttypedesc is the required entity class object, which can be used in combination with your own code.

This method may report a null pointer, solve it by itself in combination with the situation, and judge whether it is null.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>