将ArrayList转换为TreeSet

Eug*_*ene 1 java collections

我有一个ArrayList<Card> cards = new ArrayList<Card>我需要转换成的TreeSet<Card>.为此我做:

new TreeSet<Card>(cards)
Run Code Online (Sandbox Code Playgroud)

毕竟我的大小TreeSet等于1. Card该类实现Comparable接口.我做错了什么或不做什么?

Old*_*eon 7

如果使用提供的接口(即总是返回)Card,ArrayList求值中的所有s 都相等,那么您最终只能得到一个条目.Comparablecompare0TreeSet