Java playing cards (Fight the Landlord, the order of the cards in the hand)【Comparator】

Basic sorting, from big to small (sort according to the index copied in advance):

    /**
     * 基本排序·Card的id由大到小
     * @param list
     * @return
     */
    public static List<Card> DescCard(List<Card> list){
        Comparator<Card> cc=new Comparator<Card>() {
            @Override
            public int compare(Card o1, Card o2) {
                return o1.getIndex()-o2.getIndex();
            }
        };
        Collections.sort(list,cc);//正序
        Collections.reverse(list);//倒序
        return list;
    }

Effect picture:

In this hand, the landlord won with his hole cards.

Guess you like

Origin blog.csdn.net/feng8403000/article/details/114795273