整数のタプルの Set を Java で作成しようとしています。
例えば:
class Tuple
{
int first;
int second;
public Tuple(int i, int j)
{
this.first=i;
this.second=j;
}
}
そして、次のようなセットを設定しようとしています:
Set pairs = new HashSet<Tuple>();
pairs.add(new Tuple(1,2));
pairs.add(new Tuple(1,2));
pairs.add(new Tuple(1,2));
いくつかのタプル オブジェクトの場合。しかし、それでも次の方法で重複を取得しています:
System.out.println("Size: " + pairs.size());
for (Tuple t : (HashSet<Tuple>) pairs) {
System.out.println(t.toString());
}
誰でも重複を取り除くのを助けることができますか?