HashSet<List<int>> hs = new HashSet<List<int>>();
List<int> list1 = new List<int>();
list1.Add(1);
list1.Add(2);
List<int> list2 = new List<int>();
list2.Add(1);
list2.Add(2);
hs.Add(list1);
hs.Add(list2);
Console.WriteLine(hs.Count);
The above code prints '2'. Should it not be '1'? The same in java will print '1'.
List<int>is a reference type, therefore,list1 != list2. You need to pass anIEqualityComparerto the constructor of the HashSet if you want to have custom comparison logic.